Windows下Nginx+Web.py+FastCGI服務搭建

來源:互聯網
上載者:User

標籤: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服務搭建

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.