python - nginx uwsgi 和 cgi python 脚本

标签 python nginx cgi uwsgi

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

现在我的并发症:

我的脚本是前段时间写的,不是为 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 --

问题出在哪里?请帮忙。

提前致谢。

最佳答案

好的。我没读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

关于python - nginx uwsgi 和 cgi python 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10252306/

相关文章:

python - Py2Exe本地服务器不执行CGI

python - 使用 python 2 和 smtplib 发送电子邮件时出现错误

python - 运行 for 循环获取图像时不显示图像

html - 样式表在 nginx 虚拟机中不起作用

linux - 使用 NGINX 反向代理下载约 80kb 后挂起/失败

node.js - 多个端口上的 Node nginx 代理,同一域不起作用

linux - 执行不带扩展名的 CGI 文件

Python CGIHTTPServer 默认目录

python - 如何在 tkinter 中创建日期选择器?

python - 无法导入名称 import_by_path