linux下nginx+python+fastcgi部署總結(web.py版)

在上一篇文章linux下nginx+python+fastcgi部署總結(django版)中,咱們部署了nginx+django+fastcgi的環境,此次咱們來部署一下nginx+web.py+fastcgi。
其實web.py上的官方網站已經說的比較清楚了,原文以下:
http://webpy.org/cookbook/fastcgi-nginx
這裏主要講一下一些原文沒有照顧到的地方。html

一.安裝依賴
spawn-cgi
fluppython

二.配置nginx
在server配置項下增長linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
location / {     #這兩種方法均可以,只不過spawn-cgi啓動的方法不一樣     #fastcgi_pass 127.0.0.1:9002;     fastcgi_pass unix:webpy.sock;  
    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 GATEWAY_INTERFACE CGI/1.1;     fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;     fastcgi_param REMOTE_ADDR $remote_addr;     fastcgi_param REMOTE_PORT $remote_port;     fastcgi_param SERVER_ADDR $server_addr;     fastcgi_param SERVER_PORT $server_port;     fastcgi_param SERVER_NAME $server_name;     fastcgi_param SERVER_PROTOCOL $server_protocol;     fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;     fastcgi_param PATH_INFO $fastcgi_script_name; }

三.一個簡單的index.pynginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python # -*- coding: utf-8 -*-  import web 
 
urls = ("/.*", "hello") app = web.application(urls, globals())  class hello:
    def GET(self):
        return 'Hello, world!'  if __name__ == "__main__":
    web.wsgi.runwsgi = lambda func, addr=None: web.wsgi.runfcgi(func, addr)     app.run()

並執行:web

1
chmod +x index.py

四.啓動web.py
啓動:django

1
2
#spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -a 127.0.0.1 -p 9002 & spawn-fcgi -P `pwd`/webpy.pid -f /home/dantezhu/htdocs/ngx_web/index.py -s /home/dantezhu/nginx/sbin/webpy.sock &

中止:vim

1
kill -9 `cat webpy.pid`

五.啓動nginx
與上一篇文章同樣,這裏再也不贅述。bash

六.加入到rc.local中,自動啓動app

1
2
3
/home/dantezhu/nginx/sbin/start.shsudo -u dantezhu /home/dantezhu/htdocs/ngx_django/mysite/start.shsudo -u dantezhu /home/dantezhu/htdocs/ngx_web/start.sh

OK,就是這樣啦~post

原創文章,版權全部。轉載請註明:轉載自Vimer的程序世界 [ http://www.vimer.cn ]

本文連接地址: http://www.vimer.cn/?p=2267

相關文章
相關標籤/搜索