Setting up Nginx and uWSGI on different servers

Mo J. Mughrabi asked:

I’ve done before many setups of both uWSGI for django applications and flask for python-plugin under ubuntu along with Nginx as web server. I’ve always done it in one box..

As now, we are having a security need to separate application servers from web servers. I cannot seem to find a way to get it to work, uWSGI sockets not accessible beyond local host.

Below is an example to one setup

uWSGI / domain.ini

vhost = true
plugins = python
master = true
enable-threads = true
processes = 1
wsgi-file = /app/xx-env/xx/rr/misc/settings/sites/default/
virtualenv = /app/xx-env/
chdir = /app/snowflake-env/rr
touch-reload = /app/xx-env/xx/rr/misc/settings/sites/default/uwsgi-reload

Here is my nginx conf

server {
        listen 80;
        access_log /var/log/nginx/access.xx.log;
        error_log /var/log/nginx/error.xx.log;

        location / {
                try_files $uri @uwsgi;
        location @uwsgi {
            include uwsgi_params;

Any ideas on how I could accomplish this? any hints would be very much appreciated.

My answer:

Your nginx configuration is trying to pass to port 9002, but your uWSGI is configured to listen on port 9001. One of these two needs to be changed so that the ports match.

You also need to ensure that the host firewalls permit the traffic between your servers.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.