1
votes

I have created a flask app and up to this point have been using the default flask server for creating/testing it. Now i want to deploy it to a server. I am using uwsgi and nginx, though i am pretty new to both. i know there are a lot of guides and questions about similar things, but i couldnt find the solution after looking through as much as i could understand

The following is from my uwsgi log :

machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /home/ben/flask/MLS-Flask
detected binary path: /home/ben/flask/MLS-Flask/mls-flask-ve/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 1024
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 /home/ben/flask/MLS-Flask/mls_uwsgi.sock fd 3
Python version: 3.3.3 (default, Dec 30 2013, 16:29:41)  [GCC 4.4.7 20120313 (Red Hat    4.4.7-4)]
Set PythonHome to /home/ben/flask/MLS-Flask/mls-flask-ve
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x11755d0
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72760 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
added /home/ben/flask/MLS-Flask/ to pythonpath.
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x11755d0 pid: 2926 (default app)
 *** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 2926, cores: 1)

I am assuming the uwsgi is at least running? I am fairly new to this so i am not quite sure that the problem is.

my nginx config is :

server{

    listen  8080;
    charset utf-8;

    location / {try_files $uri @app; }
    location @app {
        include uwsgi_params;
        uwsgi_pass unix:/home/ben/flask/MLS-Flask/mls_uwsgi.sock;
    }
}

my uwsgi ini is :

[uwsgi]

uid = nginx
gid = nginx

base = /home/ben/flask/MLS-Flask

home = %(base)/mls-flask-ve
pythonpath = %(base)

chdir = /home/ben/flask/MLS-Flask

module = runp

#socket file's location
socket = /home/ben/flask/MLS-Flask/mls_uwsgi.sock

#permissions for the socket file
chmod-socket = 666

#variable that holds a flask application inside the module imported
callable = app

#location of log file
logto = /var/log/uwsgi/%n.log

and the file the uwsgi ini is running is my flask app:

from app import app


if __name__ == "__main__":
    app.run(debug = False, port = 8080)

I may have some extraneous stuff in my uwsgi ini or nginx config, but i am not sure if those would necessarily be the problems. Can anyone see any reasons why this might not be working? I am currently getting a 502 bad gateway error on localhost:8080, so i am guessing it has something to do with my flask, uwsgi ini/socket.

i appreciate any help.

2
I posted this question a while ago, see if you can get something out of it . stackoverflow.com/questions/17112805/… - z atef

2 Answers

0
votes

It turned out my nginx user didnt have access to the socket because the / and /home/ directory was owned by the root group and root user. I ended up giving full access to the owner and group all the way from / directory to the socket (this probably is not the safest solution security wise, but i can further refine it after i get everything working.)

0
votes

I had the same problem :

  1. Always check socket permissions by using ls -lhtr
  2. Try putting socket in /run/myapp/mysock.sock folder
  3. Create an empty sock file in this folder vi mysock.sock
  4. Set permissions of this empty file to have full access by your user and group stated in the service. chown user:group /run/myapp/mysock.sock