First look at the Configuration:
Server {
Listen 80;
Server_name localhost;
Access_log logs/access. log main;
Error_log logs/error. log warn;
Location /{
Fastcgi_pass 127.0.0.1: 3033;
Include fastcgi_django.conf;
}
Location ^ ~ /Media {
Alias D:/Studio/gtca/gtdevice/media;
Access_log off;
}
Location ^ ~ /Media/admin {
Alias D: \ Studio \ gtca \ Lib \ site-packages \ django \ contrib \ admin \ media;
Access_log off;
}
Location ~ * ^. + \. (Jpg | jpeg | gif | png | ico | css | zip | tgz | gz | rar | bz2 | doc | xls | exe | pdf | ppt | txt | tar | mid | midi | wav | bmp | rtf | js | mov) {
Root D:/Studio/gtca/gtdevice/media /;
Access_log off;
Expires 30d;
}
}
Fastcgi_django.conf:
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param QUERY_STRING $ query_string;
Fastcgi_param REQUEST_METHOD $ request_method;
Fastcgi_param CONTENT_TYPE $ content_type;
Fastcgi_param CONTENT_LENGTH $ content_length;
Fastcgi_param REQUEST_URI $ request_uri;
Fastcgi_param DOCUMENT_URI $ document_uri;
Fastcgi_param DOCUMENT_ROOT $ document_root;
Fastcgi_param SERVER_PROTOCOL $ server_protocol;
Fastcgi_param GATEWAY_INTERFACE CGI/1.1;
Fastcgi_param SERVER_SOFTWARE nginx/$ nginx_version;
Fastcgi_param REMOTE_ADDR $ remote_addr;
Fastcgi_param REMOTE_PORT $ remote_port;
Fastcgi_param SERVER_ADDR $ server_addr;
Fastcgi_param SERVER_PORT $ server_port;
Fastcgi_param SERVER_NAME $ server_name;
Pay attention to two issues (lessons learned ):
- To disable nginx, you must useNginx-s quitDo not shut down the cmd shell. nginx also has a Working Process (if worker_processes 1 is configured by default, two nginx processes are running ). I didn't pay attention to this at first, and I was not familiar with the configuration. After half a day, I was not successful. It turns out that it was caused by the failure of the working process.
- Do not include the SCRIPT_NAME in fastcgi. conf in the parameters passed to django. Django usage
PATH_INFOTo match urlpatterns. IfPATH_INFOAnd SCRIPT_NAME are both set$fastcgi_script_nameDjango creates an empty string for all requests. My website needs to authenticate and jump to next. It never works because of this reason.
- Note that in the above configuration, both the media on the website and the django media are configured, so that nginx can be directly returned to the client, because django does not care about static files.