Go to: Install and set nginx + Python + flup + Django in windows, and run it as a service!

Source: Internet
Author: User
Install and set nginx + Python + flup + Django in windows and run it as a service! 1Add this article to favorites. This article was published one month ago and already exists. 41Total times of reading 0Comments 1Add this article to favorites

Download and install

Main Site

Http://nginx.org/

Download

Http://nginx.org/en/download.html

Download stable version

Http://nginx.org/download/nginx-0.7.67.zip

Books

Http://nginx.org/en/docs/

Chinese Wiki

Http://wiki.nginx.org/NginxChs

Run nginx.exe to view http: // localhost:

Welcome to nginx!

Stop nginx Process

Manually Perform Batch Processing and copy several rows. Because two nginx.exe files are running, taskkill is provided by window.

X:/> taskkill/f/IM nginx.exe

Configuration

The configuration file is in CONF/nginx. conf

Assume that the project is in E:/project/Python/mysite

Corresponding configuration file/cygdrive/e/project/Python/mysite

Corresponding configuration file (or such) E:/project/Python/mysite

Suppose python is installed in F:/python25/

Corresponding configuration file/cygdrive/f/python25/

Corresponding configuration file writing (or such) F:/python25/

Test both writing methods.

Use this section to replace CONF/nginx. conf and back up the original file.

# 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_connections 64;
}


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 {
Listen 80;
SERVER_NAME localhost;

# Root/cygdrive/D/html;
Root/cygdrive/e/project/Python/mysite;
# Debugging
# Root E:/project/Python/mysite;
Index index.html index.htm;

Charset UTF-8;

# Access_log logs/host. Access. Log main;

Location ^ ~ /Media /{
Alias F:/python25/lib/Site-packages/Django/contrib/admin/Media /;
# Debugging
# Alias/cygdrive/f/python25/lib/Site-packages/Django/contrib/admin/Media /;
}
# Static Resources
Location ~ * ^. + /. (HTML | JPG | JPEG | GIF | PNG | ICO | CSS | zip | tgz | GZ | RAR | bz2 | Doc | XLS | exe | PDF | PPT | TXT | tar | mid | MIDI | WAV | BMP | RTF | JS) $
{
Expires 30d;
Break;
}

Location /{
# Specify the host and port of FastCGI
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;
}

# Error_page 404/404 .html;

# Redirect server error pages to the static page/50x.html
#
Error_page 500 502 503 x.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 Fig: 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;
#}
}

# 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;
# SERVER_NAME localhost;

# SSL on;
# Ssl_certificate cert. pem;
# Ssl_certificate_key cert. Key;

# Ssl_session_timeout 5 m;

# Ssl_protocols SSLv2 SSLv3 tlsv1;
# Ssl_ciphers all :! ADH :! Export56: RC4 + RSA: + high: + medium: + low: + SSLv2: + exp;
# Ssl_prefer_server_ciphers on;

# Location /{
# Root HTML;
# Index index.html index.htm;
#}
#}

}

Install flup

Introduction

Flup is a wsgi (web gateway interface) implemented in Python)

Main Site

Http://www.saddi.com/software/flup/dist/

Download

Http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz

Extract

D:/Setup/Python/flup-1.0.2/flup-1.0.2

Install

X:/decompress the directory> Python setup. py install

Success prompt

Installed F:/python25/lib/Site-packages/flup-1.0.2-py2.5.egg

Processing dependencies for flup = 1.0.2

Finished processing dependencies for flup = 1.0.2

Or in this way, as long as the environment is configured (Click here)

X:/under any directory> easy_install http://www.saddi.com/software/flup/dist/flup-1.0.2-py2.5.egg

FastCGI mode of Django

Port 8051 provides services for nginx, which is written in the nginx configuration file. You can also make it into a bat processing service.

X:/Project> Python manage. py runfcgi method = threaded host = 127.0.0.1 Port = 8051

Manage. py runfcgi contains a bunch of parameters. view the parameters.

X:/Project> Manage. py help runfcgi

All configured to view

Http: // localhost/

OK

Reference

Nginx + FastCGI + flup + Django installed on Windows

Http://hi.baidu.com/sinomazing/blog/item/611b8516e701d912972b43c9.html

Nginx configuration details

Http://www.westphp.com/bbs/thread-62-1-1.html

Configure the python environment for nginx

Http://zhiwei.li/text/2008/10/configure the pythonenvironment for nginx/

Python development: flup, wsgi, and Django

Http://www.fresh3g.net/blog/tag/django/

In this article (install nginx, flup, Django FastCGI mode) based on further download window provided by the management package http://www.microsoft.com/downloads/details.aspx? Familyid = 9d467a69-57ff-4ae7-96ee-b18c4790cffd & displaylang = EN downloaded a 12 m Installation File and installed it to % ProgramFiles %/Windows resource kits/tools/2 files required Hypothesis
Nginx.exe in D:/Setup/nginx/nginx-0.7.67/nginx-0.7.67/
Python is installed on F:/python25/project on E:/project/Python/mysite/
Change the following path.

Put the nginx service setting file in the directory e:/project/Python/doc/nginx/and then create a batch under it. Reg_service.batThe content is as follows: "% ProgramFiles %/Windows resource kits/tools/instsrv.exe" Nginx"% ProgramFiles %/Windows resource kits/tools/srvany.exe" pausesrvany.exe is called by the service, and the service name is in bold. Avoid conflict with the existing service name. Continue to create Reg_service.regWindows Registry Editor Version 5.00 for the Registry type [HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/ Nginx/Parameters] "application" = "D: // setup // nginx // nginx-0.7.67 // nginx-0.7.67 // nginx.exe" "appparameters" = "" appdirectory "=" D: // setup // nginx // nginx-0.7.67 // nginx-0.7.67 // "note that the path is written with a double slash, bold is the service name, seemingly case-insensitive Continue to build Start_service.batIt is used to manually start the service during debugging. After the computer is restarted, the Net start of the service is automatically started. NginxPause Continue to build Stop_service.batUsed to stop the service. net stop NginxRem pausetaskill/f/IM nginx.exe taskkill/f/IM nginx.exe pause because there are at least two nginx.exe processes, after the net stop service, only one process can be stopped. Other processes must use the window command taskkill to stop the process. Continue to build Del_service.batUsed to delete a service SC Delete NginxThe nginx registration procedure has been prepared for pause, and the following services are ready for running again. Please refer to the following link for more information: set FastCGI service below and put the following service setting file in this directory e: /project/Python/doc/mysite/copy the above five files to this directory and then process @ Reg_service.bat"% ProgramFiles %/Windows resource kits/tools/instsrv.exe" Fastcgi_mysite"% ProgramFiles %/Windows resource kits/tools/srvany.exe" Pause @ Reg_service.regWindows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE/system/CurrentControlSet/services/ Fastcgi_mysite/Parameters] "application" = "F: // python25 // python.exe" "appparameters" = "manage. PY runfcgi method = threaded host = 127.0.0.1 Port = 8051 "" appdirectory "=" E: // project // Python // mysite //" @ Start_service.batNet start Fastcgi_mysitePause @ Stop_service.batNet stop Fastcgi_mysitePause @ Del_service.batSC Delete Fastcgi_mysitePause After the above files are ready, run reg_service.batreg_service.regstart_service.bat in E:/project/Python/doc/mysite/to start the service that Django runs on 127.0.0.1: 8051 in FastCGI mode. E: reg_service.batreg_service.service.regstart_service.bat under/project/Python/doc/nginx/starts the nginx service and enters http: // localhost/OK in the browser/
Related Article

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.