I'm developing with django on elastic beanstalk and I want to make two changes to apache configuration:
1. redirect www.domain.com to domain.com
2. redirect http://domain.com to https://domain.com
I don't have experience with apache configuration, googling it gave me the idea that I should put RewriteRules in .htaccess file.
example: How to force https on amazon elastic beanstalk without failing the health check
I couldn't find instructions on how to do it with elastic beanstalk configuration (.ebextensions), I tried to simply put a .htaccess file in my root filder and deploy but it didn't work.
Does anyone know how it's possible to add the RewriteRules in elastic beanstalk?
this is an easy solution
- ssh into your EC2 instance
- copy the contents of /etc/httpd/conf.d/wsgi.conf into a local file called wsgi.conf which will be placed in the base folder of your application
Edit the local version of wsgi.conf and add the following redirect rules within the < VirtualHost> < /VirtualHost> tags
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]Change the “/status” to whatever page you are using as a health check page.
- Save the file
Edit your < app>.conf file inside your .ebextensions directory to add a container command to copy this version of wsgi.conf over Amazon’s version
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput" leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
03_wsgireplace:
command: 'cp wsgi.conf ../wsgi.conf'
...Deploy the code.
- The deployed version of wsg.conf at /etc/httd/conf.d/wsgi.conf will now include the necessary redirect rules.
It should work and the file will be properly updated for each deployment. The only thing to watch for is if Amazon changes their base wsgi.conf file contents in the future, then your copy may no longer work.
Autor rickchristianson
I'm developing with django on elastic beanstalk and I want to make two changes to apache configuration:
1. redirect www.domain.com to domain.com
2. redirect http://domain.com to https://domain.com
I don't have experience with apache configuration, googling it gave me the idea that I should put RewriteRules in .htaccess file.
example: How to force https on amazon elastic beanstalk without failing the health check
I couldn't find instructions on how to do it with elastic beanstalk configuration (.ebextensions), I tried to simply put a .htaccess file in my root filder and deploy but it didn't work.
Does anyone know how it's possible to add the RewriteRules in elastic beanstalk?
this is an easy solution
- ssh into your EC2 instance
- copy the contents of /etc/httpd/conf.d/wsgi.conf into a local file called wsgi.conf which will be placed in the base folder of your application
Edit the local version of wsgi.conf and add the following redirect rules within the < VirtualHost> < /VirtualHost> tags
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/status https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]Change the “/status” to whatever page you are using as a health check page.
- Save the file
Edit your < app>.conf file inside your .ebextensions directory to add a container command to copy this version of wsgi.conf over Amazon’s version
container_commands:
01_syncdb:
command: "django-admin.py syncdb --noinput" leader_only: true
02_collectstatic:
command: "django-admin.py collectstatic --noinput"
03_wsgireplace:
command: 'cp wsgi.conf ../wsgi.conf'
...Deploy the code.
- The deployed version of wsg.conf at /etc/httd/conf.d/wsgi.conf will now include the necessary redirect rules.
It should work and the file will be properly updated for each deployment. The only thing to watch for is if Amazon changes their base wsgi.conf file contents in the future, then your copy may no longer work.
Autor rickchristianson
0 commentaires:
Enregistrer un commentaire