Skip to content

Instantly share code, notes, and snippets.

@efoken
Last active August 29, 2015 14:04
Show Gist options
  • Save efoken/c9b58c7d62a3309a1039 to your computer and use it in GitHub Desktop.
Save efoken/c9b58c7d62a3309a1039 to your computer and use it in GitHub Desktop.
nginx.conf for Django projects
upstream django {
server unix:///tmp/example.com.sock;
}
server {
server_name www.example.com example.com;
rewrite ^ https://example.com$request_uri? permanent;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
charset utf-8;
client_max_body_size 75M;
# Configure error templates.
error_page 404 /srv/www/example.com/example/templates/404.html;
error_page 500 /srv/www/example.com/example/templates/500.html;
# Enable gzip compression.
gzip on;
gzip_min_length 1100;
gzip_buffers 4 32k;
gzip_types text/plain application/x-javascript text/xml text/css;
gzip_vary on;
location /media { # STATIC_URL
alias /srv/www/example.com/public/media;
expires 30d;
}
location /static { # MEDIA_URL
alias /srv/www/example.com/public/static;
expires 30d;
}
# Serve favicon and SEO-related stuff.
location ~ ^/(favicon\.ico|apple-touch-icon.*\.png)$ {
alias /srv/www/example.com/public/$1;
log_not_found off;
}
location = /crossdomain.xml { alias /srv/www/example.com/public/crossdomain.xml; }
location = /humans.txt { alias /srv/www/example.com/public/humans.txt; }
location = /robots.txt { alias /srv/www/example.com/public/robots.txt; }
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /srv/www/example.com/uwsgi_params;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment