简单的nginx + uWSGI设置问题

时间:2013-10-06 07:28:08

标签: python nginx uwsgi no-framework

我有大量的python脚本(为了方便大多数)生成html输出,所以我当然希望使用一个非常简单的设置来在我当前的测试环境中托管脚本。设置项目,比如Django,Flask,web2py或者其他什么,对于我需要的每一件愚蠢的事情都是太麻烦了,我只想写一个.py并浏览它而不需要配置任何其他东西,就像用php一样。 / p>

我一直在努力解决这个问题几天,因为我不确定到底出了什么问题,所以我只想用配置文件发布我当前的尝试:

nginx的:

location ~ \.py$ {
    uwsgi_pass unix:///path/to/socket;
    uwsgi_param SCRIPT_NAME $uri;
    include uwsgi_params;
}

uWSGI

[uwsgi]
plugins = python3
py-auto-reload = 1 #So I dont have to reload the service every time

test.py

def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return b"Hello World"

我在nginx和uwsgi配置中有很多很多变种,但我总是得到:

uWSGI错误

找不到Python应用程序

日志总是显示如下内容:

[pid: 10423|app: -1|req: -1/10] 10.0.20.101 () {42 vars in 675 bytes} [Sun Oct  6 08:25:51 2013] GET /test.py => generated 48 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
-
Sun Oct  6 08:26:44 2013 - unable to load app 0 (mountpoint='/var/www/test.py') (callable not found or import error)
[pid: 10423|app: -1|req: -1/12] 10.0.20.101 () {44 vars in 707 bytes} [Sun Oct  6 08:26:44 2013] GET /test.py => generated 48 bytes in 0 msecs (H
TTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)
-
Sun Oct  6 07:22:36 2013 - unable to load app 0 (mountpoint='/test.py') (callable not found or import error)
[pid: 10423|app: -1|req: -1/12] 10.0.20.101 () {44 vars in 707 bytes} [Sun Oct  6 08:26:44 2013] GET /test.py => generated 48 bytes in 0 msecs (H
TTP/1.1 500) 2 headers in 63 bytes (0 switches on core 0)

1 个答案:

答案 0 :(得分:0)

这不是WSGI应用程序的工作方式。它们通常是nginx向其发送请求的长时间运行的应用程序。您要求类似CGI的设置,因此您必须使用uWSGI CGI模块(http://uwsgi-docs.readthedocs.org/en/latest/CGI.html)。这些应用程序显然必须符合CGI标准。我不确定这是你想要的,但我强烈建议你在WSGI应用程序的工作方式上投入一些时间,因为这基本上是其他一切工作现在如何(perl / PSGI,ruby / Rack ......)

注意:您可能会发现(uWSGI)人员的配置完全管理您要完成的任务,但它们远非正常的方式。