3

I'm trying to deploy a flask app through uWSGI onto Nginx, with Fedora 20 as the OS, and i'm running into some issues.

I have the following configuration files:

NGINX - Default config with following edit:

location / { try_files $uri @yourapplication; }
location @yourapplication {
        include uwsgi_params;
        uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;
}

uWSGI:

[uwsgi]
socket = /tmp/%n.sock
wsgi-file = sjudson_app/sjudson_app.py
callable = sjudson
master = true
chmod-socket = 666
logto = /home/server/logs/uwsgi.log

First of all, when I attempt to run:

uwsgi --ini sjudson_app_uwsgi.ini

I just get:

[uWSGI] getting INI configuration from sjudson_app_uwsgi.ini

Indefinetely. Secondly, when I run it directly from the command line:

uwsgi --socket /tmp/sjudson_app_uwsgi.sock --wsgi-file sjudson_app/sjudson_app.py --callable sjudson --master --chmod-socket=666

I get:

*** Starting uWSGI 2.0.3 (32bit) on [Tue Mar 25 17:58:44 2014] ***
compiled with version: 4.8.2 20131212 (Red Hat 4.8.2-7) on 25 March 2014 16:48:01
os: Linux-3.13.6-200.fc20.i686+PAE #1 SMP Fri Mar 7 17:17:53 UTC 2014
nodename: new-host-6
machine: i686
clock source: unix
detected number of CPU cores: 2
current working directory: /home/server
detected binary path: /usr/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
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 /tmp/sjudson_app_uwsgi.sock fd 3
Python version: 2.7.5 (default, Feb 19 2014, 13:47:40)  [GCC 4.8.2 20131212 (Red Hat 4.8.2-7)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x881cc40
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 127952 bytes (124 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x881cc40 pid: 1131 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 1131)
spawned uWSGI worker 1 (pid: 1136, cores: 1)

But when I try to connect to the server I get a 502 error. I noticed this stackoverflow post: Flask, nginx, and uwsgi with a similar issue, for which the upvoted answer concerned the socket permissions not being correct. However, I do have the chmod-socket=666 argument, and looking at /tmp:

srw-rw-rw-.  1 server server    0 Mar 25 17:53 sjudson_app_uwsgi.sock

So it doesn't look to me as though that's the issue.

EDIT:

Realized I forgot to include the Nginx error message:

2014/03/26 07:58:38 [crit] 792#0: *15 connect() to unix:/tmp/sjudson_app_uswgi.sock 
failed (2: No such file or directory) while connecting to upstream, client: 
173.79.242.54, server: localhost, request: "GET / HTTP/1.1", upstream: 
"uwsgi://unix:/tmp/sjudson_app_uswgi.sock:", host: "173.79.242.54"

I'm not sure what's meant by the "no such file or directory" in this case. I know the .sock file exists, so what is it struggling to find?

HDJEMAI
  • 9,436
  • 46
  • 67
  • 93
JackGibbs
  • 230
  • 2
  • 9
  • check nginx error logs, uWSGI is starting correctly, so you need to get why nginx cannot connect to it. And when you start with "logto", logs are in the specified file, so it is normal you do not see more in the command line – roberto Mar 26 '14 at 06:03
  • I see, but that only explains why I don't see any more information when I use the --ini flag. It doesn't explain why I'm getting the 502 error, as the log has the same information as the output from the command line option I posted above. – JackGibbs Mar 26 '14 at 11:58
  • remove the logto directive and re-run uwsgi from the terminal. after that try reconnecting from nginx (be sure to always check nginx error logs). "No such file or directory" on unix sockets means there is no process listening to the socket. If it still does not work, try with tcp sockets. – roberto Mar 26 '14 at 12:57
  • Thanks a lot for the help. Unfortunately, it didn't solve the problem. What do you mean by tcp sockets? Do you mean explicitly denoting the socket to run on, such as 127.0.0.1:3031? – JackGibbs Mar 26 '14 at 13:13
  • Similar error: 2014/03/26 09:16:51 [crit] 4131#0: *1 connect() to 127.0.0.1:3031 failed (13: Permission denied) while connecting to upstream, client: 173.79.242.54, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://127.0.0.1:3031", host: "173.79.242.54" - The server is running under the default nginx user, which has only the permissions that it was given when it was created by the nginx install. Is there a group I need to add it to? – JackGibbs Mar 26 '14 at 13:18
  • permission denied while trying to connect to a tcp socket ??? are you sure you do not have something like selinux enabled or some other security system ? – roberto Mar 26 '14 at 14:50
  • Default Fedora 20 Server install. – JackGibbs Mar 26 '14 at 14:53
  • Is there a group I can add the nginx user to, or a config file I can edit, that will allow that user access to the tcp sockets without granting it too much power? – JackGibbs Mar 26 '14 at 15:00
  • 2
    start disabling selinux, tcp sockets in standard systems do not have permissions (a part for ports < 1024). After you are sure that the problems are generated by selinux policies you can start writing one for your nginx+uWSGI setup (yes, you need to invest time in understanding how selinux works) – roberto Mar 26 '14 at 15:20
  • Thanks. Disabling seems to have cleared it up, and I'll dive into the docs when I have some time this weekend and see if I can get everything configured as I'd want with it activated. If you'd like to summarize as an answer, I'll upvote and accept. – JackGibbs Mar 26 '14 at 15:34

2 Answers2

2

I had almost the exact same setup and same error message. To fix it I had to do:

  • change the socket statement in my uwsgi.ini file to:

    socket = 127.0.0.1:8081
    
  • add the following to my nginx.conf file (outside of the server statement):

    upstream uwsgi { server 127.0.0.1:8081; }
    
  • change the location statement in my nginx.conf file to:

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

This then enabled nginx and uwsgi to communicate. These instructions were taken from http://blog.djcentric.com/setting-up-uswgi-nginx-what-you-need-to-know/ .

ByteNudger
  • 1,545
  • 5
  • 29
  • 37
bmp
  • 21
  • 3
0

Please change string in nginx configuration, from
uwsgi_pass unix:/tmp/sjudson_app_uswgi.sock;
to
uwsgi_pass unix:///tmp/sjudson_app_uswgi.sock;

nnmware
  • 930
  • 5
  • 15