forked from pyzen/generic_django_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nginx.conf
68 lines (56 loc) · 1.98 KB
/
nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# see http://djangoadvent.com/1.2/deploying-django-site-using-fastcgi/
# see http://wiki.nginx.org/NginxConfiguration
# from http://wiki.nginx.org/Pitfalls:
# BAD: Root inside location block
# "Putting root inside of a location block will work and it's perfectly valid. What's wrong is when you start adding location blocks. If you add a root to every location block then a location block that isn't matched will have no root."
# WHY HERE: We want our root only for a few specific locations, everything else is to be handled by Django!
server {
listen 80;
server_name project_name.de;
# BAD:
#rewrite ^/(.*) http://www.project_name.de/$1 permanent;
rewrite ^ http://www.project_name.de$request_uri? permanent;
}
upstream project_name_app_server { # this works with gunicorn; name must be unique if you run several projects!
server 127.0.0.1:8001 fail_timeout=0; # change port!
}
server {
listen 80;
server_name www.project_name.de;
access_log /var/www/project_name/logs/access.log;
error_log /var/www/project_name/logs/error.log error;
location ^~ /static {
alias /var/www/project_name/releases/current/project_name/static_collection;
expires 24h;
break;
}
location = /favicon.ico {
root /var/www/project_name/releases/current/project_name/static;
expires 24h;
break;
}
location ^~ /medialibrary {
root /var/www/project_name;
expires 24h;
break;
}
# location /media { # project media
# rewrite ^/media/(.*) /static/$1 permanent;
# break;
# }
location / {
# Don't use IF, see http://wiki.nginx.org/IfIsEvil
# Nginx knows try_files since 0.7.27
try_files $uri @django;
}
location @django {
include /etc/nginx/fastcgi_params; # SCRIPT_INFO must not be defined!
#if (!-f $request_filename) {
proxy_pass http://project_name_app_server; # for gunicorn
#proxy_buffering off; # for streaming
#break;
#}
#fastcgi_pass 127.0.0.1:8001; # for fcgi / Change port!
break;
}
}