NGINX,带有CGI插件的uWSGI,Python脚本-502坏网关

NGINX,带有CGI插件的uWSGI,Python脚本-502坏网关,python,nginx,cgi,uwsgi,Python,Nginx,Cgi,Uwsgi,我想使用uWSGI和CGI插件来处理从NGINX传递到.py文件的所有请求 NGINX服务器配置: location ~ \.py$ { include uwsgi_params; uwsgi_modifier1 9; uwsgi_pass unix:/var/www/html/cgi-bin/wsgi.sock; } uWSGI配置: [uwsgi] plugin-dir = /usr/lib/uwsgi/plugins plugins =

我想使用uWSGI和CGI插件来处理从NGINX传递到
.py
文件的所有请求

NGINX服务器配置:

location ~ \.py$ {
    include         uwsgi_params;
    uwsgi_modifier1 9;
    uwsgi_pass      unix:/var/www/html/cgi-bin/wsgi.sock;
}
uWSGI配置:

[uwsgi]
plugin-dir = /usr/lib/uwsgi/plugins
plugins = cgi
cgi = /var/www/html/cgi-bin
cgi-allowed-ext = .py
cgi-helper = .py=python
master = true
processes = 5
socket = wsgi.sock
chmod-socket = 664
vacuum = true
die-on-term = true
uWSGI启动输出:

$ sudo -u www-data uwsgi --ini uwsgi.ini 
[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.18 (64bit) on [Fri Oct 18 15:27:33 2019] ***
compiled with version: 7.4.0 on 18 October 2019 12:14:16
os: Linux-4.15.0-65-generic #74-Ubuntu SMP Tue Sep 17 17:06:04 UTC 2019
nodename: some-host
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 4
current working directory: /var/www/html/cgi-bin
detected binary path: /usr/bin/uwsgi
your processes number limit is 15501
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address wsgi.sock fd 3
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 437424 bytes (427 KB) for 5 cores
*** Operational MODE: preforking ***
initialized CGI path: /var/www/html/cgi-bin
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 6868)
spawned uWSGI worker 1 (pid: 6869, cores: 1)
spawned uWSGI worker 2 (pid: 6870, cores: 1)
spawned uWSGI worker 3 (pid: 6871, cores: 1)
spawned uWSGI worker 4 (pid: 6872, cores: 1)
spawned uWSGI worker 5 (pid: 6873, cores: 1)
/var/www/html/cgi-bin/
中有两个文件:

  • info.py
  • some.py
如果我用任何其他文件名打开URL,我会从uWSGI得到
404
错误-这很好。但是,如果我打开一个带有实际脚本名的URL,那么我会从uWSGI获得
500
(因此从NGINX获得
502坏网关

网址:

  • http://localhost/another.py
  • http://localhost/info.py
  • http://localhost/some.py
  • 输出:

    [pid: 9606|app: -1|req: -1/1] 127.0.0.1 () {42 vars in 624 bytes} [Fri Oct 18 15:40:50 2019] GET /another.py => generated 9 bytes in 0 msecs (HTTP/1.1 404) 2 headers in 71 bytes (0 switches on core 0)
    [pid: 9604|app: -1|req: -1/2] 127.0.0.1 () {42 vars in 618 bytes} [Fri Oct 18 15:41:01 2019] GET /info.py => generated 0 bytes in 15 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
    [pid: 9606|app: -1|req: -1/3] 127.0.0.1 () {42 vars in 618 bytes} [Fri Oct 18 15:41:05 2019] GET /some.py => generated 0 bytes in 15 msecs (HTTP/1.1 500) 0 headers in 0 bytes (0 switches on core 0)
    
    很明显,它找到了文件(
    info.py
    some.py
    ),但uWSGI出现
    500
    错误的原因是什么?这两种配置是否都有问题

    下面是一个Python脚本:

    def application(environ, start_response):
        start_response('200 OK', [('Content-Type', 'text/html')])
        return [ "Ololo".encode("utf-8") ]
    
    带有CGI插件的uWSGI通过以下方式安装:

    我写了一封信,详细介绍了这件事

    curl http://uwsgi.it/install | bash -s cgi /tmp/uwsgi
    sudo mv /tmp/uwsgi /usr/bin