Skip to content

Instantly share code, notes, and snippets.

@asmallteapot
Created March 14, 2012 19:00
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save asmallteapot/2038673 to your computer and use it in GitHub Desktop.
Save asmallteapot/2038673 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;
}
}
@joelcrocker
Copy link

In order to match favicon.* (assuming you don't want to match an empty extension), the favicon location regex should be:
^/favicon\.(\w+)$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment