1

I have a ton of python scripts that (for convenience mostly) generate html output, so naturally I would like to use a very simple setup to host the scripts in my current test environment. Setting up projects in say, Django, Flask, web2py or whatever, for every silly thing I need is too much of a hassle, I just want to write a .py and browse it without configuring anything else, pretty much as with php.

I've been struggling with this for a couple of days because I'm not sure exactly what is wrong, so I'll just post my current attempt with the config files:

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"

I have many many MANY variations in the nginx and uwsgi config but I always get:

uWSGI Error

Python application not found

And the log always shows stuff like these:

[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)
4

1 回答 1

0

这不是 WSGI 应用程序应该如何工作的。它们通常是 nginx 将请求传递到的长时间运行的应用程序。您要求进行类似 CGI 的设置,因此您必须使用 uWSGI CGI 模块(http://uwsgi-docs.readthedocs.org/en/latest/CGI.html)。这些应用程序显然必须符合 CGI 标准。我不确定这是否是您想要的,但我强烈建议您花点时间了解 WSGI 应用程序的工作方式,因为这基本上是当今其他所有工作的方式(perl/PSGI、ruby/Rack ......)

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

于 2013-10-06T07:39:02.527 回答