Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
111 lines (97 sloc) 3.32 KB
# www fix
server {
# www.example.com -> example.com
#server_name www.example.com;
#rewrite ^ $scheme://example.com$request_uri? permanent;
# www.example.com -> example.com
server_name example.com;
rewrite ^ $scheme://www.example.com$request_uri? permanent;
}
# www (application) server
server {
# set server_name to - $host - to accept every domain name
# and to separate their memcached keys
server_name www.example.com;
listen 80 default_server deferred;
listen 443 default_server deferred ssl;
root /data/env/myproject;
access_log /data/log/nginx/$host-access.log;
error_log /data/log/nginx/example.com-error.log error;
# will go maintenance if upstream is down
recursive_error_pages on;
# SSL
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
#ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
location ~ ^/(favicon\.ico|robots\.txt)$ {
root /data/app/myproject/staticfiles;
log_not_found off;
access_log off;
expires 30d;
try_files $uri =204;
}
location / {
# try to fetch from memcached
set $memcached_key "$server_name$request_uri";
memcached_pass 127.0.0.1:11211;
expires 1h;
# not fetched from memcached, fallback
error_page 404 405 502 = @fallback;
}
# if memcached fails, fallback to uwsgi upstream
location @fallback {
uwsgi_pass uwsgicluster;
error_page 502 503 504 =503 @maintenance;
}
# no upstream available, go maintenance
location @maintenance {
add_header Retry-After 10000;
index /app/templates/503.html;
}
}
# static server
server {
server_name static.example.com;
listen 80;
listen 443 ssl;
root /data/app/myproject/staticfiles;
access_log /data/log/nginx/$host-access.log;
error_log /data/log/nginx/static.example.com-error.log error;
expires 24h;
# SSL
#ssl_certificate cert.pem;
#ssl_certificate_key cert.key;
#ssl_session_timeout 5m;
#ssl_protocols SSLv2 SSLv3 TLSv1;
#ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
#ssl_prefer_server_ciphers on;
# hot link protection
valid_referers none blocked localhost .example.com $host;
if ($invalid_referer) {
return 404;
}
location ~ ^/(favicon\.ico|robots\.txt)$ {
log_not_found off;
access_log off;
expires 30d;
try_files $uri =204;
}
# media - user uploaded files
location /media/ {
alias /data/app/myproject/media/;
index index.html;
#autoindex on;
}
# Django admin media
location /media/admin/ {
alias /data/app/myproject/staticfiles/admin/;
}
# everything else
location / {
index index.html;
#autoindex on;
}
}