flask under nginx + uwsgi


Question

we're developing a flask application but after 4 hours trying to configure the server I can't figure it out.

Here's the thing:

  • the vm is accessible through xx.xx.xx.xx:81

  • on this server, my app is at : /var/hg/repositories/data/test.py

I'd like to access this application through xx.xx.xx.xx:81/ws

This is what I did with nginx :

 location = /var/hg/repositories/data { rewrite ^ /var/hg/repositories/data/; }
     location /ws { try_files $uri @ws; }
     location @ws {
        include uwsgi_params;
        uwsgi_param SCRIPT_NAME /var/hg/repositories/data;
        uwsgi_modifier1 30;
        uwsgi_pass unix:/tmp/uwsgi.sock;
     }

I have a yaml file to lunch uwsgi :

uwsgi:
  socket: 127.0.0.1:9090
  master: 1
  workers: 1
  chmod-socket: 666
  auto-procname: 1
  python-path: .
  pidfile: /tmp/uwsgi.pid
  daemonize: /var/log/uwsgi.log
  module: test:app

Going to xx.xx.xx.xx:81 gives me the classic nginx welcome message.

Going to xx.xx.xx.xx:81/ws gives me a 404.

What am I doing wrong?

after conf update, i have

    location = /var/hg/repositories/data/
    location /var/hg/repositories/data/ { try_files $uri @web }
    location @ws {
             uwsgi_pass unix:/tmp/uwsgi.sock;
    }

my uwsgi conf :

uwsgi:
  socket: unix:/tmp/uwsgi.lock
  master: 1
  workers: 1
  chmod-socket: 666
  auto-procname: 1
  pidfile: /tmp/uwsgi.pid
  deamonize: /var/log/uwsgi.log
  manage-script-name: true
  mount: /ws=/var/hg/repositories/data/test.py
  callable: app
1
0
11/24/2012 6:10:18 PM

You have to "mount" the app in uWSGI, currently you have "mounted" it as empty SCRIPT_NAME

mount: /ws=test.py

callable: app

(remove the 'module' directive) will do the trick.

I suggest you to avoid nginx managing SCRIPT_NAME as it is not too smart about that, and using modifier1 30 is really an ugly hack.

Just remove both uwsgi_param and uwsgi_modifier1 from nginx and add manage-script-name: true to uWSGI

2
11/24/2012 6:04:15 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon