Skip to content

Instantly share code, notes, and snippets.

@edhowler
Last active April 9, 2021 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edhowler/518381ff4a340045317af1657b1de24c to your computer and use it in GitHub Desktop.
Save edhowler/518381ff4a340045317af1657b1de24c to your computer and use it in GitHub Desktop.
Elastic Beanstalk configuration to redirect HTTP to HTTPS (place this inside .ebextensions folder and deploy)
files:
/etc/nginx/conf.d/elasticbeanstalk/00_application2.conf:
owner: root
group: root
mode: "000644"
content: |
location / {
set $redirect 0;
if ($http_x_forwarded_proto != "https") {
set $redirect 1;
}
if ($http_user_agent ~* "ELB-HealthChecker") {
set $redirect 0;
}
if ($redirect = 1) {
return 301 https://$host$request_uri;
}
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
container_commands:
removeconfig:
command: "sudo rm -f /etc/nginx/conf.d/elasticbeanstalk/00_application.conf"
nginx_reload:
command: "sudo service nginx reload"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment