nginx + uwsgi: -- unavailable modifier requested: 0 --
Asked Answered
C

6

90

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 --
Congregationalism answered 25/5, 2012 at 3:26 Comment(1)
On Ubuntu uwsgi is started as a service: service uwsgi start.Goldoni
S
116

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 = python3 to the [uwsgi] section and it should solve this problem.

For further 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

Subtle answered 15/6, 2012 at 17:46 Comment(7)
The equivalent of this (yum plugin install + uwsgi config change) just worked for me on CentOS7.Swiercz
Have been breaking my head, unable to fix this issue. Thank you !Euphonium
What about alpine linux?Jenifer
I don't know where the file is for the "individual uwsgi app config". Could you be more specific? Is this my uwsgi app's ini file? The /etc/something file? Maybe paste a sample of what the file contents look like so I know what you are referring to? And a typical location for the file?Shrinkage
It's been quite a while since I had to worry about this (7 years in fact) but I do indeed mean the uwsgi app's ini file. As you can probably imagine, I no longer have any config files lying around but a quick google search produced this (seemingly) handy guide. As for the location of the ini file, it could realistically live almost anywhere. If you were feeling particularly adventurous you could even serve up that ini file from another web server anywhere in the world, like so: uwsgi --ini http://uwsgi.it/configs/myapp.iniSubtle
Note that the plugin depends on the versions in /usr/lib64/uwsgi (for example), and on a centos box of mine I had to use plugins = python36.Parody
For Python 3, I had to do plugins = python3Retinue
C
29

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

Congregationalism answered 25/5, 2012 at 4:3 Comment(1)
Please write wide answer with more details and set question as resolved with @Subtle answerEellike
B
15

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.

Beethoven answered 28/5, 2012 at 23:32 Comment(0)
D
8

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;
}
Discursion answered 5/2, 2014 at 1:23 Comment(0)
M
8

Modify your ini file by added plugins line.

    [uwsgi]
    plugins         = python3
Mcmahon answered 29/11, 2020 at 18:14 Comment(0)
S
2

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
Shower answered 2/10, 2019 at 19:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.