【发布时间】:2016-10-25 23:02:57
【问题描述】:
我想在 ElasticBeanstalk 中我的实例的 apache 指令中插入一些行。 (我的实例是运行 Python 2.7 的 64 位 Amazon Linux 2016.03 v2.1.0,用于运行带有 mod_wsgi 的 Django)。
我创建了一个文件“configuration_httpd.py”:
# -*- coding: utf-8 -*-
import os
import fileinput
current_dir = os.path.dirname(os.path.abspath(__file__))
custom_conf = open(current_dir+'/httpd.conf','r').read()
try:
for line in fileinput.input('/etc/httpd/conf.d/wsgi.conf', inplace=1):
if line.startswith('</VirtualHost>'):
print custom_conf
print line,
else:
print line,
except OSError:
print "Error '/etc/httpd/conf.d/wsgi.conf' unknown"
它在带有 .ebextensions/django.config 文件的部署上执行:
packages:
yum:
libjpeg-turbo-devel: []
libpng-devel: []
container_commands:
01_setup_apache:
command: "python configure_httpd.py"
02_migrate:
command: "python manage.py migrate"
leader_only: true
03_collectstatic:
command: "python manage.py collectstatic --noinput"
option_settings:
aws:elasticbeanstalk:application:environment:
DJANGO_SETTINGS_MODULE: "djangoproject.settings"
PYTHONPATH: "/opt/python/current/app/djangoproject:$PYTHONPATH"
aws:elasticbeanstalk:container:python:
WSGIPath: "djangoproject/wsgi.py"
这个文件被执行了,但是'/etc/httpd/conf.d/wsgi.conf'文件是完整的。
为什么?
当我使用 ssh 登录到我的实例时,我可以使用 sudo 运行脚本“configure_httpd.py”并且它可以工作。
为什么这个脚本在部署时不起作用?
请帮忙。谢谢
【问题讨论】:
-
这是一个权限问题,因为当您部署时,您不会以 root 用户身份进行部署,并且配置文件必须由 root 拥有。您必须检查此命令是否适用于 python 命令中的“sudo python manage.py collectstatic --noinput”。
-
不是权限问题。经过一番测试,我了解到该文件修改得很好,但在 container_commands 之后被重写。
-
那么问题现在解决了吗?
标签: django apache amazon-web-services amazon-elastic-beanstalk mod-wsgi