1

I am consistently getting a bad gateway 502 error with the setup below when I run uwsgi --ini /root/code/poetree/uwsgi.ini. However, as you see in the logs at the end, the app is starting fine with the workers booting up (as seen in ps aux | grep uwsgi). One other observation is that the server block below (in /etc/nginx/sites-available/conf) is working fine for fetching the static data in /audio, but is getting the gateway error when trying to load any dynamic pages.

If I instead use app.flask_app.run(host='0.0.0.0', port=8080), then I can see the page no problem, so this tells me it's something to do with the uwsgi / nginx.

uwsgi.ini

[uwsgi]
base = /root/code/poetree
app = app
module = %(app)
callable = flask_app
pythonpath = /usr/local/lib/python2.7/dist-packages
socket = %(base)/%n.sock                                                                                                                                                         
master = true
processes = 5
chmod-socket    = 666
logto = /var/log/uwsgi/%n.log

/etc/nginx/sites-available/conf

server {
        listen 80;

        root /;

        server_name <IP_ADDRESS>

        location /audio/ {
                root /data;
                try_files $uri $uri/ =404;
        }
        location / {
                try_files $uri @poetree;
        }
        location @poetree {
                 include uwsgi_params;
                 uwsgi_pass unix:/root/code/poetree/uwsgi.sock;
        }
}

/var/log/uwsgi/uwsgi.log:

*** Starting uWSGI 2.0.6 (64bit) on [Wed Jul 16 11:48:13 2014] ***
compiled with version: 4.8.2 on 16 July 2014 11:38:51
os: Linux-3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014
nodename: cinjon
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /root/code/poetree
detected binary path: /usr/local/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
your processes number limit is 3751
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address /root/code/poetree/uwsgi.sock fd 3
Python version: 2.7.6 (default, Mar 22 2014, 23:03:41)  [GCC 4.8.2]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x11af010
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 436608 bytes (426 KB) for 5 cores
*** Operational MODE: preforking ***
added /usr/local/lib/python2.7/dist-packages/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x11af010 pid: 580 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 580)
spawned uWSGI worker 1 (pid: 583, cores: 1)
spawned uWSGI worker 2 (pid: 584, cores: 1)
spawned uWSGI worker 3 (pid: 585, cores: 1)
spawned uWSGI worker 4 (pid: 586, cores: 1)
spawned uWSGI worker 5 (pid: 587, cores: 1)
user592419
  • 5,103
  • 9
  • 42
  • 67

1 Answers1

-1

I am assuming these lines explains the issue and correct me if i am wrong at somewhere

!!! no internal routing support, rebuild with pcre support !!!
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 

To solve the pcre issue in uwsgi refer this thread might help you

Also, it would be better to run the uwsgi to prevent running under root instead of the current user.

Edit2:

I would suggest you to try with reverse proxy pass instead of uwsgi params.

location / {
        proxy_pass  http://127.0.0.1:5000/;
        proxy_set_header    Host    $host;
        proxy_set_header    X-Real-IP   $remote_addr;
    }

Change the port no

Community
  • 1
  • 1
Nava
  • 6,276
  • 6
  • 44
  • 68
  • Thanks Nava, I made the change specified in the thread and that warning no longer appears. However, the same error is occurring. I've updated the debug logs as they show now. – user592419 Jul 16 '14 at 15:50
  • edited question..you can try reverse proxy pass just run your app in `screen` as usual `python app.py` and try to forward the request adn this would help to spot the bug – Nava Jul 17 '14 at 04:59
  • Usually you don't need internal routing so pcre is not an issue. – jwalker Jul 20 '14 at 11:56