六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 476|回复: 0

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

[复制链接]
 楼主| 发表于 2013-11-26 18:05:18 | 显示全部楼层 |阅读模式
windows下安装设置Nginx+python+flup+django,并设为服务运行
下载安装

it论坛主站  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:!EXPORt*56: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

it论坛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\"
it论坛@ 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 本文摘自 it论坛:http://hi.baidu.com/honfei/item/4eb039c7589bbd57bdef69d2

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表