標籤:web.py filename 瞭解 訪問 log tools tps pos ati
在搭建之前,有必要瞭解下什麼是fastcgi,但鑒於我自己也不大瞭解,這裡就不搬門弄斧了,請參考各種百科和官網資料.
1.資源下載
python:戳這裡
webpy:戳這裡
flup:戳這裡
nginx:戳這裡
建議先把python裝好,然後裝setuptools,easy_install,接著用easy_install命令可以直接下載安裝web.py,flup.
nginx下載解壓即可用,不過需要稍微配置一下.
2.nginx配置
安裝完成測試下,開啟nginx.exe再訪問localhost顯示檔案夾html下的index.html內容就沒什麼問題了.
conf下的nginx.conf是它的設定檔,這東西參數好多,配置參數詳解候可以參考這篇文章,而且配置之前記得留備份啊
我們現在需要改的東西如下.
server { listen 80; server_name www.xspython.com; location / { root "D:\Project\Python\web"; index index.html index.htm; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_script_name; fastcgi_pass 127.0.0.1:8008; }}
設定完後用命令列的方式
nginx –s stop 停止服務
nginx –t 測試組態檔案是否有錯誤
nginx 啟動服務
然後訪問localhost,會顯示pyweb/www/下的index.html(自己隨便寫個hello world吧)
3.web.py
建立一個code.py檔案,其內容如下
import weburls = ( ‘/‘, ‘index‘, "/list", "list",)class index: def GET(self): return "Hello, world123456!"class list: def GET(self): return "Hello, list!"if __name__ == "__main__": app = web.application(urls, globals()) app.run()
然後命令列啟動它,像這樣python code.py 8008 fastcgi,這裡的8008即第二步設定檔中設定連接埠號碼,如果不一致是無法正常訪問的.
現在訪問localhost/hello,看是不是返回了Hello, world?
現在訪問www.xspython.com,看是不是返回了Hello, world?
Windows下Nginx+Web.py+FastCGI服務搭建