uwsgi + python + nginx + 随意文件执行
我在用Nginx和uwsgi来运行一些Python代码。
我想把uwsgi绑定到一个文件夹,这样我在浏览器里从服务器调用任何.py文件时,它都能执行。就像PHP那样,比如说/index.php执行那个文件,/login.php执行那个文件。
这样做可以吗?还是说我只能在uwsgi里明确指定一个模块、应用或文件?
这是我的初始化语法:
/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;
}
目前,当我尝试访问网站根目录(比如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]
有什么想法吗?
谢谢!