2012-04-20 244 views
5

我遇到了问题。我有一个Python脚本。你可以称之为CGI脚本。它在Apache2下工作正常,但在我关闭系统之前只剩下一个它永远运行。新系统使用nginx。 我在配置虚拟主机的解决方案上搜索时,按照许多人的建议配置了uwsgi,以便此脚本运行。 我已经使用uwsgi wiki上的第一个例子来确认我已正确配置nginx,并且它可以与uwsgi进行通信。像魅力一样工作。nginx uwsgi和cgi python脚本

现在我的并发症:

我的剧本是前一段时间写的,而不是专为WSGI,我也想/可以重写它。

所以我为uwsgi安装了cgi模块并尝试使用它。我得到的是502错误。没有任何正在执行的uwsgi。

这里是我的配置我使用这个应用程序:

[uwsgi] 
plugins = cgi 
socket = 127.0.0.1:9010 
cgi = /=/usr/share/test/ 
cgi-allowed-ext = .py 
cgi-helper = .py=python 

这里是代码我在index.py(测试脚本):

#!/usr/bin/python 
print "Content-type: text/html\n\n" 
print "<html><body><h1>It works!</h1></body></html>" 

我尝试测试uwsgi与以下命令:

/usr/sbin/uwsgi --http :9011 --ini /etc/uwsgi/test.ini --master 

,这里是输出我得到:

[uWSGI] getting INI configuration from /etc/uwsgi/test.ini 
*** Starting uWSGI 1.1.2 (64bit) on [Fri Apr 20 15:26:33 2012] *** 
compiled with version: 4.4.6 20110731 (Red Hat 4.4.6-3) on 19 April 2012 15:09:37 
current working directory: /home/user 
detected binary path: /usr/sbin/uwsgi 
your memory page size is 4096 bytes 
detected max file descriptor number: 1024 
lock engine: pthread mutexes 
uWSGI http bound on :9011 fd 3 
uwsgi socket 0 bound to TCP address 127.0.0.1:9010 fd 6 
your server socket listen backlog is limited to 100 connections 
*** Operational MODE: single process *** 
initialized CGI mountpoint:/= /usr/share/test/ 
*** no app loaded. going in full dynamic mode *** 
*** uWSGI is running in multiple interpreter mode *** 
spawned uWSGI master process (pid: 6727) 
spawned uWSGI worker 1 (pid: 6728, cores: 1) 
spawned uWSGI http 1 (pid: 6729) 
-- unavailable modifier requested: 0 -- 
-- unavailable modifier requested: 0 -- 
-- unavailable modifier requested: 0 -- 
-- unavailable modifier requested: 0 -- 

问题在哪里?请帮忙。

在此先感谢。

+0

伟大的你找到了解决方案,但是最好是将它作为答案添加它,这使得阅读帖子的其他人更清楚。谢谢! – CharlesB 2012-04-20 20:13:28

+0

@CharlesB这是我的计划,但它让我等了7个小时。当我找到解决方案时,我想马上发布。我会在今天晚些时候或明天晚些时候将其发表意见。谢谢。 – sashk 2012-04-21 00:15:59

+0

这是一种提醒,这样你就不会忘记你可以知道addd的答案:) – CharlesB 2012-04-21 07:13:25

回答

6

好的。我没有读uwsgi WIKI够好。我所要做的只是将--http-modifier1 9添加到命令行开关,或将uwsgi_modifier1 9;添加到nginx配置。

location/{ 
    include /etc/nginx/uwsgi_params; 
    uwsgi_modifier1 9; 
    uwsgi_pass 127.0.0.1:9010; 
} 

/usr/sbin/uwsgi --http :9011 --http-modifier1 9 --ini /etc/uwsgi/test.ini --master