nginx + django on windows

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   

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

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.