Skip to content

Instantly share code, notes, and snippets.

@stephenash
Created October 22, 2014 21:00
Show Gist options
  • Save stephenash/6f185a8ef00588a5cc0d to your computer and use it in GitHub Desktop.
Save stephenash/6f185a8ef00588a5cc0d to your computer and use it in GitHub Desktop.

Revisions

  1. stephenash created this gist Oct 22, 2014.
    7 changes: 7 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    I needed a way to have my Django ElasticBeanstalk application automatically redirect HTTP requrests to HTTPS. Rick Christianson wrote a post [1] about how to do this by overwriting the `wsgi.conf` file with one that was slightly modified to support the HTTP to HTTPS redirect.

    Building off the shoulders of giants, I wanted to do the same, but not have to keep a copy of the config file in my local source directory. Christianson even points out in his post that if ElasticBeanstalk ever changes it's template for the `wsgi.conf` file, those updates would not be overwritten and you wouldn't get their benefits. To get around that problem, I used `sed` to insert the new lines into the `wsgi.conf` file.

    ## References
    1. http://rickchristianson.wordpress.com/2013/11/02/updating-wsgi-automatically-in-amazon-aws/
    2. http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-container_commands
    4 changes: 4 additions & 0 deletions app.config
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    container_commands:
    01_http_to_https_redirect:
    command:
    sed -i '/\<VirtualHost \*:80\>/a RewriteEngine On\nRewriteCond %{HTTP:X-Forwarded-Proto} !https\nRewriteRule \!/robots.txt https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]' /opt/python/ondeck/wsgi.conf