Source

fabdeploy / fabdeploy / config_templates / nginx_gunicorn.config

map $scheme $my_ssl {
    default off;
    https on;
}

# For AWS EC2 with load balancer please use:
#
# map $server_port $my_scheme {
#     default http;
#     443 https;
# }
#
# map $my_scheme $my_ssl {
#     default off;
#     https on;
# }

server {
    sendfile on;
    tcp_nopush on;
    tcp_nodelay off;

    listen 80;
    server_name {{ server_name }};
    access_log /var/log/nginx/{{ server_name }}-access.log;
    error_log /var/log/nginx/{{ server_name }}-error.log;

    charset utf-8;
    keepalive_timeout 5;
    client_max_body_size 8m;

    gzip_types text/plain text/xml text/css application/javascript application/x-javascript application/json;

    location / {
        proxy_pass http://localhost:{{ gunicorn_port }};
        proxy_set_header Host              $host;
        proxy_set_header X-Real-IP         $remote_addr;
        proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Ssl   $my_ssl;
        proxy_redirect off;
    }

    location /static {
        root {{ active_django_link }};
        autoindex off;
        expires 1M;
    }

    location /static/admin {
        alias {{ active_env_link }}/lib/python2.6/site-packages/django/contrib/admin/media;
        autoindex off;
        expires 10m;
    }

    error_page 500 502 503 504  /500.html;
    location = /500.html {
        root {{ active_django_link }}/templates;
    }

    error_page 404  /404.html;

    location = /robots.txt {
        alias {{ active_django_link }}/static/robots.txt;
    }
}

server {
    listen 80;
    server_name www.{{ server_name }};
    rewrite ^ https://{{ server_name }}$uri permanent;
}