Nginx + uwsgi: ——不可用的修饰符请求: 0——

Ubuntu 12.04,nginx 1.2.0,uwsgi 1.0.3.

我使用以下命令启动 uwsgi:

uwsgi -s 127.0.0.1:9010 -M -t 30 -A 4 -p 4 -d /var/log/uwsgi.log

对于每个请求,nginx 用502回复,uwsgi 写入以下代码行:

-- unavailable modifier requested: 0 --
46659 次浏览

Solved by installing uwsgi-plugin-python3 plugin and adding --plugin python3 option to uwsgi start command

Im starting uwsgi from upstart on Ubuntu. I solved the problem by running apt-get install uwsgi-plugin-python, and then adding plugins=python to my application.ini in /etc/uwsgi/applications-available.

Original answer

For Python 2 on Ubuntu 11.10, using upstart, install the python plugin for uWSGI with apt-get install uwsgi-plugin-python and if you're using an ini file to configure your uWSGI app, then add plugins = python to the [uwsgi] section and it should solve this problem.

Edit: Updated for Python 3 and Ubuntu 17.10

For Python 3 on Ubuntu 17.10, using systemd, install the python plugin for uWSGI with apt-get install uwsgi-plugin-python3 and if you're using an ini file to configure your uWSGI app, then add plugins = python to the [uwsgi] section and it should solve this problem.

For more information on getting started with python/uWSGI apps, including how to configure them using an ini file then please take a look at this handy guide

from http://uwsgi-docs.readthedocs.org/en/latest/ThingsToKnow.html, "To route requests to a specific plugin, the webserver needs to pass a magic number known as a modifier to the uWSGI instances. By default this number is set to 0, which is mapped to Python."

I'm using 9 for a bash script and it's working. the numbers and their meanings are on this page: http://uwsgi-docs.readthedocs.org/en/latest/Protocol.html

in my nginx configuration:

location ~ .cgi$ {
include uwsgi_params;
uwsgi_modifier1 9;
uwsgi_pass 127.0.0.1:3031;
}

I'm using Ubuntu 18.04 with Python 3. Below is the exact config I used to get it working.

You must have the Python 3 uWSGI plugin installed:

apt install uwsgi-plugin-python3

Your Nginx site configuration should point to your uWSGI socket. Make sure the port matches the configuration in the later steps.

    location / {
uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;
}

Reload the Nginx config to reflect the changes you just made:

systemctl reload nginx

You can use command-line arguments or an ini file for configuration. I created uwsgi.ini. Make sure the socket address matches your nginx config.

[uwsgi]
socket = 127.0.0.1:9090
chdir = /var/www
processes = 4
threads = 2
plugins = python3
wsgi-file = /var/www/app.py

My app.py just has a basic example:

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

Now start the uWSGI server from the command line:

uwsgi uwsgi.ini

Modify your ini file by added plugins line.

    [uwsgi]
plugins         = python3