I want to insert some lines in apache directive of my instances in ElasticBeanstalk. (My instances are 64bit Amazon Linux 2016.03 v2.1.0 running Python 2.7 for running Django with mod_wsgi).
I have created a file "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"
It's executed on deployments with .ebextensions/django.config file :
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"
This file is executed but the file '/etc/httpd/conf.d/wsgi.conf' is intact.
Why ?
When I log into my instance with ssh I can run the script "configure_httpd.py" with sudo and it works.
Why this script doesn't work at deployment ?
Any help please. Thank you
After some hours on google, I find that the directive <Directory>
allows to use rewrite rules from outside <VirtualHost>
directives. Exemple :
<Directory /opt/python/current/app/>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
</Directory>
Put this in a file and copy it in /etc/httpd/conf.d in container_commands.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.