Skip to content

Instantly share code, notes, and snippets.

@openrijal
Forked from asmallteapot/nginx.conf
Created September 9, 2016 13:51
Show Gist options
  • Save openrijal/e4694115e51f1e97456c066e046c359a to your computer and use it in GitHub Desktop.
Save openrijal/e4694115e51f1e97456c066e046c359a to your computer and use it in GitHub Desktop.
My default Nginx configuration for serving Django projects.
# file: /etc/nginx/sites-available/example.com
# nginx configuration for example.com
server {
listen 80;
server_name example.com;
access_log /srv/www/example.com/logs/access.log;
error_log /srv/www/example.com/logs/error.log;
# pass root to django
location / {
include uwsgi_params;
uwsgi_pass unix://tmp/example.sock;
# disallow .py, .wsgi, and .conf
}
# serve django static files
location /static {
root /srv/www/example.com/site;
}
# alias robots.txt to static
location /robots.txt {
alias /srv/www/example.com/site/static/robots.txt;
}
# alias favicon.* to static
location ~ ^/favicon.(\w*)$ {
alias /srv/www/example.com/site/static/favicon.$1;
}
# alias stylesheets to static
location ~ ^/([^/]*\.css)$ {
alias /srv/www/example.com/site/static/css/$1;
}
# serve django uploaded media
location /media {
root /srv/www/example.com/site;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment