下載安裝php
主站css
http://nginx.org/html
下載python
http://nginx.org/en/download.htmlnginx
下載穩定版django
http://nginx.org/download/nginx-0.7.67.zipwindows
書瀏覽器
http://nginx.org/en/docs/session
中文wikiapp
http://wiki.nginx.org/NginxChs
解壓,運行nginx.exe,查看 http://localhost/,沒問題就出現:
Welcome to nginx!
停止nginx進程
手工,作個bat批處理,多複製幾行,由於至少有2個nginx.exe在運行中,taskkill是Window自帶的
X:/> taskkill /f /im nginx.exe
配置
配置文件在 conf/nginx.conf
假設項目在E:/project/python/mysite
對應配置文件的寫法 /cygdrive/E/project/python/mysite
對應配置文件的寫法(或者是這種) E:/project/python/mysite
假設Python安裝在 F:/Python25/
對應配置文件的寫法 /cygdrive/F/Python25/
對應配置文件的寫法(或者是這種) F:/Python25/
兩種寫法都測試一下
先用這段替換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_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;
# 使用哪行,調試一下
#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/;
# 使用哪行,調試一下
#alias /cygdrive/F/Python25/Lib/site-packages/django/contrib/admin/media/;
}
# 靜態資源
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 / {
# 指定 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 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;
#}
}
# 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 5m;
# 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;
# }
#}
}
安裝flup
簡介
flup是用python實現的WSGI(網頁網關接口)
主站
http://www.saddi.com/software/flup/dist/
下載
http://www.saddi.com/software/flup/dist/flup-1.0.2.tar.gz
解壓
D:/setup/python/flup-1.0.2/flup-1.0.2
安裝
X:/解壓目錄>python setup.py install
成功提示
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
或者用這種方式,只要環境配置好了(點這裏 )
X:/任意目錄下>easy_install http://www.saddi.com/software/flup/dist/flup-1.0.2-py2.5.egg
django的fastcgi模式
在8051這個端口爲nginx提供服務,對應nginx配置文件中寫的。仍是作成bat處理,能夠作成服務形式
X:/項目>python manage.py runfcgi method=threaded host=127.0.0.1 port=8051
manage.py runfcgi裏面有一堆參數,查看參數
X:/項目> manage.py help runfcgi
都配置好了查看
http://localhost/
ok
參考
在windows上裝 nginx + fastcgi + flup +django 終於裝好了
http://hi.baidu.com/sinomazing/blog/item/611b8516e701d912972b43c9.html
nginx詳細配置說明
http://www.westphp.com/bbs/thread-62-1-1.html
爲nginx配置python環境
http://zhiwei.li/text/2008/10/爲nginx配置python環境/
Python 開發:flup、WSGI及Django
http://www.fresh3g.net/blog/tag/django/
下載window提供的管理包
下載了一個12M的安裝文件
默認安裝到 %ProgramFiles%/Windows Resource Kits/Tools/
須要裏面的2個文件
假設
nginx.exe在 D:/setup/nginx/nginx-0.7.67/nginx-0.7.67/
python安裝在 F:/python25/
項目在 E:/project/python/mysite/
下面的路徑稍微注意換一下
那就把 nginx 服務設置文件放在這個目錄 E:/project/python/doc/nginx/
再在其下建個批處理
reg_service.bat 內容以下
"%ProgramFiles%/Windows Resource Kits/Tools/instsrv.exe"
Nginx "%ProgramFiles%/Windows Resource Kits/Tools/srvany.exe"
pause
其中的srvany.exe就是被服務所調用的,粗體是服務名稱,注意避免和現有服務名衝突
繼續在那個目錄下建個
reg_service.reg 註冊表類型的
Windows Registry Editor Version 5.00
[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//"
注意路徑的雙斜槓寫法,粗體是服務名,貌似大小寫無關
繼續建
start_service.bat 用於調試時手工啓動服務,重啓電腦後是自動啓動這個服務的
繼續建
stop_service.bat 用於中止服務
net stop
Nginx
rem pause
taskkill /f /im nginx.exe
taskkill /f /im nginx.exe
taskkill /f /im nginx.exe
taskkill /f /im nginx.exe
pause
由於 nginx.exe 進程有至少2個, net stop 中止服務後,只能中止一個,其它的進程須要使用window自帶命令taskkill去停止
繼續建
del_service.bat 用於刪除服務
到這裏已經準備好了 nginx 的註冊步驟,等下面 的服務也準備好,再運行
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
下面設置 fastcgi 的服務
那就把下面的服務設置文件放在這個目錄 E:/project/python/doc/mysite/
把上面的5個文件複製到這個目錄裏再處理
@
reg_service.bat
"%ProgramFiles%/Windows Resource Kits/Tools/instsrv.exe"
fastcgi_mysite "%ProgramFiles%/Windows Resource Kits/Tools/srvany.exe"
pause
@
reg_service.reg
Windows 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.bat
net start
fastcgi_mysite
pause
@
stop_service.bat
net stop
fastcgi_mysite
pause
@
del_service.bat
sc delete
fastcgi_mysite
pause
上面的文件都準備好後
依次運行 E:/project/python/doc/mysite/ 下的
reg_service.bat
reg_service.reg
start_service.bat
啓動了 django用fastcgi方式運行在127.0.0.1:8051的服務
繼續運行 E:/project/python/doc/nginx/ 下的
reg_service.bat
reg_service.reg
start_service.bat
ok