nginx + uwsgi: -- unavailable modifier requested: 0 --

NginxUwsgiUbuntu 12.04

Nginx Problem Overview


Ubuntu 12.04, nginx 1.2.0, uwsgi 1.0.3.

I start uwsgi with the following command:

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

On each request nginx replies with 502 and uwsgi writes to log the following line:

-- unavailable modifier requested: 0 --

Nginx Solutions


Solution 1 - Nginx

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

Solution 2 - Nginx

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

Solution 3 - Nginx

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.

Solution 4 - Nginx

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;
}

Solution 5 - Nginx

Modify your ini file by added plugins line.

    [uwsgi]
    plugins         = python3

Solution 6 - Nginx

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLisioView Question on Stackoverflow
Solution 1 - NginxSHaKieView Answer on Stackoverflow
Solution 2 - NginxLisioView Answer on Stackoverflow
Solution 3 - NginxshaneView Answer on Stackoverflow
Solution 4 - Nginxjcomeau_ictxView Answer on Stackoverflow
Solution 5 - NginxMinhaj AnsariView Answer on Stackoverflow
Solution 6 - NginxJordan MackView Answer on Stackoverflow