Nginx + fastcgi + django Practice Notes

Source: Internet
Author: User

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 usagePATH_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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.