windows下安裝設定Nginx+python+flup+django,並設為服務運行!
1人收藏此文章, 收藏此文章 發表於1個月前 , 已有
41次閱讀 共
0個評論
1人收藏此文章
下載安裝
主站
http://nginx.org/
下載
http://nginx.org/en/download.html
下載穩定版
http://nginx.org/download/nginx-0.7.67.zip
書
http://nginx.org/en/docs/
中文wiki
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/
在這一篇( 安裝nginx,flup,django的fastcgi模式 )的基礎上更進一步下載window提供的管理組件http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en下載了一個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 用於調試時手工啟動服務,重啟電腦後是自動啟動這個服務的net start
Nginxpause繼續建
stop_service.bat 用於停止服務net stop
Nginxrem pausetaskkill /f /im nginx.exetaskkill /f /im nginx.exetaskkill /f /im nginx.exetaskkill /f /im nginx.exepause因為 nginx.exe 進程有至少2個, net stop 停止服務後,只能停止一個,其它的進程需要使用window內建命令taskkill去中止繼續建
del_service.bat 用於刪除服務sc delete
Nginxpause到這裡已經準備好了 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_mysitepause@
stop_service.bat net stop
fastcgi_mysitepause@
del_service.bat sc delete
fastcgi_mysitepause上面的檔案都準備好後依次運行 E:/project/python/doc/mysite/ 下的reg_service.batreg_service.regstart_service.bat啟動了 django用fastcgi方式運行在127.0.0.1:8051的服務繼續運行 E:/project/python/doc/nginx/ 下的reg_service.batreg_service.regstart_service.bat啟動了 nginx 服務用瀏覽器進入 http://localhost/ok原貼:1、http://firehuman.blog.163.com/blog/static/573311201052455233391/2、http://firehuman.blog.163.com/blog/static/573311201052511846779/