我在Nginx上使用uwsgi來運行一些Python代碼。uwsgi + python + nginx + willy nilly文件執行
我想將uwsgi綁定到一個目錄,並使其呈現在瀏覽器中從服務器調用的任何.py文件。我在想PHP,在這裏(/index.php執行該文件,/login.php執行該文件)。
這是否可能?或者我只能在uwsgi中明確指定一個模塊/應用程序/文件?
這裏是我的init語法:
/opt/uwsgi/uwsgi -s 127.0.0.1:9001 -M 4 -t 30 -A 4 -p 4 -d /var/log/uwsgi.log --pidfile /var/run/uwsgi.pid --pythonpath /srv/www
我認爲這會允許/srv/www
作爲其中任何.py文件被執行的文件夾。
這裏是我的nginx的配置:
server {
listen 80;
server_name DONT_NEED_THIS;
access_log /srv/www/logs/access.log;
error_log /srv/www/logs/error.log;
location/{
root /srv/www;
# added lines
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
}
目前的情況是,當我嘗試調用Web根(即www.site.com/)我得到一個:
wsgi application not found
隨着以下index.py文件:
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
def application(environ, start_response):
status = '200 OK'
output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
任何想法?
謝謝!
原諒我一個小白...是一般來說,Python就像PHP(即每個文件執行)?或者是典型的標準應用程序框架的單一文件門戶? – eastydude5 2011-06-06 04:57:57
不,它不像PHP一般,雖然你可以做CGI的東西。建議並最好使用WSGI,它基本上是Web應用程序和Web服務器之間交互的定義。 Python擁有豐富的WSGI服務器和框架生態系統,大大簡化了應用程序開發,部署,輔助互操作性等等,這是唯一的出路。 – zeekay 2011-06-06 05:06:02