Windows下Nginx + flup + fastcgi + webpy 开发应用环境的设置

 

Windows 下可以以 fastcgi 的方式运行 webpy 网站应用,下面详细说明如何设置开发环境。

一、 安装 nginx

1 、首先到 nginx 的官方网站 ( www.nginx.org ) 下载最新版本 nginx windows 直接运行包,将其解压至任一目录,最好不要解压至有空格的目录中。例如我的是:

D:/nginx-0.9.5

2、 然后设置 conf 下的 nginx.conf 文件如下,详细的设置命令可参考张宴的 nginx 书籍:

#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 10; #gzip on; server { listen 80; server_name localhost; #root /cygdrive/D/html; root F:/projects/www/mysite; # 使用哪行,调试一下 #root E:/project/python/mysite; index index.html index.htm; charset utf-8; #access_log logs/host.access.log main; location ^~ /media/ { alias C:/Python27/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; # } #} }

3、 然后运行 nginx.exe

4、 在浏览器中打开地址: http://127.0.0.1/ 。见到 nginx 的运行界面证明安装成功

 

二、 安装 python ,我安装的是 2.7.1 版本

三、 安装 flup ,我的是 1.0.2 。下载,解压,运行 setup.py install 即可。

四、 安装 webpy ,我的是 0.34 版。下载,解压,运行 setup.py install 即可。

五、建立一个项目文件夹,例如: mysite 。并在此目录下建立项目文件,例如: index.py 。内容如下:

 

 

 

#!/usr/bin/python # -*- coding: UTF-8 -*- import web urls = ( '/.*', 'hello' ) app = web.application(urls, globals()) class hello: def GET(self): return 'Hello, Yavobo. ' if __name__ == "__main__": app.run()

运行此文件如下:

Index.py 8051 fastcgi

此处注意一点:端口必须与 nginx.conf 中的“fastcgi_pass 127.0.0.1:8051; ”一致。否则打不开网页。

完成。

 

你可能感兴趣的:(Windows下Nginx + flup + fastcgi + webpy 开发应用环境的设置)