首页 > Windows开发 > 详细

nginx + django on windows

时间:2014-07-11 19:39:45      阅读:501      评论:0      收藏:0      [点我收藏+]

It‘s quite simple to run django on nginx on windows. Here are some key steps to follow -

1. Download nginx/windows from http://nginx.org/en/download.html

2. Unzip the pckage (like nginx-1.7.2.zip) to a folder in your machine)

3. Install flup (fastcgi connecting nginx and django) from https://pypi.python.org/pypi/flup 

4. Configure nginx config file. Some key section is shown below,

server {
        listen       8000;
        server_name  localhost;
        
        location ~ ^/ {
            fastcgi_pass 127.0.0.1:8001;
            #fastcgi_index index.html
            
            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;
        }
    }

Nginx would listen on 8000 port, and when you access the django site, it would pass the request to your django application listening on 8001 port. 

Also add the following section to the conf file to tell nginx to render static files in your django application. 

location ~ ^/static/ {
            root   "C:/Users/yufa/Desktop/Document/Study/Django/sqlmonitor/";
            expires 30d;
           # root  html;
           # index  index.html index.htm;
            break;
        }

 

5. Start nginx (nginx.exe)

6. Start django, binding to nginx. 

python manage.py runfcgi host=127.0.0.1 port=8001 protocol=fcgi method=threaded

7. It‘s done, open a browser, and try http://127.0.0.1:8000

 

 

 

nginx + django on windows,布布扣,bubuko.com

nginx + django on windows

原文:http://www.cnblogs.com/fangwenyu/p/3833547.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!