我在 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;
}
就目前而言,当我尝试调用 web root(即 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]
有任何想法吗?
谢谢!