windows下安装设置Nginx+python+flup+django,并设为服务运行!

下载安装

主站

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提供的管理包
下载了一个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 Nginx
pause

继续建  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 用于删除服务
sc delete Nginx
pause
到这里已经准备好了 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
启动了 nginx 服务

用浏览器进入  http://localhost/
ok

原贴:
1、http://firehuman.blog.163.com/blog/static/573311201052455233391/
2、http://firehuman.blog.163.com/blog/static/573311201052511846779/
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值