Nginx + Django Configuration under Windows

Source: Internet
Author: User

1. Download Nginx, go to http://nginx.org/en/download.html download, I downloaded the 1.8 stable version.

2. configuration file/conf/nginx.conf

#user nobody;Worker_processes 1;#error_log Logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;Events {Worker_connections1024;}    HTTP {include mime.types; Default_type Application/octet-stream; #Log_format main ' $remote _addr-$remote _user [$time _local] "$request" '    #' $status $body _bytes_sent ' $http _referer '    #' "$http _user_agent" "$http _x_forwarded_for";    #access_log Logs/access.log main;sendfile on; #Tcp_nopush on;    #keepalive_timeout 0;Keepalive_timeout 65; #gzip on;Server {Listen80;        server_name localhost; #CharSet koi8-r;#root/cygdrive/d/myjango; #access_log Logs/host.access.log main; Location/{root HTML;          Index index.html index.htm; }        #error_page 404/404.html;        #Redirect Server error pages to the static page/50x.html        #Error_page 500 502 503 504/50x.html; Location= /50x.html {root html; }        #Proxy The PHP scripts to Apache listening on 127.0.0.1:80        #        #Location ~ \.php$ {        #Proxy_pass http://127.0.0.1;        #}        #Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000        #        #Location ~ \.php$ {        #root html;        #Fastcgi_pass 127.0.0.1:9000;        #Fastcgi_index index.php;        #Fastcgi_param Script_filename/scripts$fastcgi_script_name;        #include Fastcgi_params;        #}        #deny access to. htaccess files, if Apache ' s document Root        #concurs with Nginx ' s one        #        #Location ~/\.ht {        #deny all;        #}Location ~* ^.+\.              (Html|jpg|jpeg|gif|png|ico|css|js) $ {root D:/myjango;              Expires 30d; break; }      Location~ ^/static/{root D:/myjango; Expires 30d; break; }    Location~ ^/{fastcgi_pass 127.0.0.1:8051;              Fastcgi_param path_info $fastcgi _script_name;              Fastcgi_param Request_method $request _method;              Fastcgi_param query_string $query _string;              Fastcgi_param Content_Type $content _type;              Fastcgi_param content_length $content _length;              Fastcgi_param server_protocol $server _protocol;              Fastcgi_param server_port $server _port;              Fastcgi_param server_name $server _name;              Fastcgi_pass_header Authorization;          Fastcgi_intercept_errors off; }          }    #Another virtual host using mix of ip-, name-, and port-based configuration    #    #server {    #Listen 8000;    #Listen somename:8080;    #server_name somename alias Another.alias;    #Location /{    #root html;    #index index.html index.htm;    #    }    #}    #HTTPS Server    #    #server {    #listen 443 SSL;    #server_name localhost;    #ssl_certificate Cert.pem;    #Ssl_certificate_key Cert.key;    #Ssl_session_cache shared:ssl:1m;    #ssl_session_timeout 5m;    #ssl_ciphers high:!anull:! MD5;    #ssl_prefer_server_ciphers on;    #Location /{    #root html;    #index index.html index.htm;    #    }    #}}

None of the other changes, the most important part is to add the fastcgi configuration and the static file in the server{} configuration item.

3. Python installation Flup (Python's fastcgi component)

Pip Install Flup

4. Running the Nginx server

d:\users\rick.xu>cd D:\nginx-1.8.0\nginx-1.8. 0D:\nginx-1.8.0\nginx-1.8.0>  Start Nginx.exe

5. Run your Django project with fastcgi

d:\users\rick.xu>cd D:\myjangoD:\myjango>python manage.py runfcgi method=threaded host= 127.0.0.1 port=8051

6. When you refresh localhost, you'll see your interface.

Nginx + Django Configuration under Windows

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.