1

I'm serving my app with uWSGI using uwsgi --http-socket 127.0.0.1:3031 -w app:app, which works when I go to 127.0.0.1:3031 in a browser. I want to use Nginx, so I told it to uwsgi_pass to that url, but now I get a 502 Bad Gateway error. How do I put uWSGI behind Nginx?

server {
    listen 8080;
    server_name 127.0.0.1;

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

    location /static {
        alias /static/folder/location;
    }
}
2016/05/16 19:50:09 [error] 6810#0: *4 upstream prematurely closed
connection while reading response header from upstream, client:
127.0.0.1, server: 127.0.0.1, request: "GET / HTTP/1.1", upstream: 
"uwsgi://127.0.0.1:3031", host: "127.0.0.1:8080"

2 Answers 2

1

You can use http-socket between nginx and uWSGI. For example, if you launch your python app with uWSGI:

uwsgi --http-socket 127.0.0.1:3031 --wsgi-file application.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191

Configure Nginx with:

location / {
    proxy_pass http://127.0.0.1:3031/;
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use socket, not http-socket.

uwsgi --socket 127.0.0.1:3031 -w app:app

http-socket makes uWSGI act like a web server that speaks HTTP, and is not correct if you're using Nginx, since it understands uWSGI directly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.