rjhazeld
Posts: 38
Joined: Mon Feb 16, 2015 9:19 am

Problem with unix socket nginx-uwsgi

Tue Feb 06, 2018 11:30 am

I'm trying to get a php web page to pass variables to backend python app. I get a 502 bad gateway error when I try the page. The web server is nginx and has a working php-fpm setup using a unix socket in the /run/php folder. I then added a location for uwsgi gleaned from the many guides on the web:
  • location ~ .py$ {
    include uwsgi_params;
    uwsgi_pass unix:/home/pi/sockets/camcon.sock;
    #uwsgi_modifier1 9;
    }
The uwsgi_config.ini contains:
  • # Socket
    socket = unix:/home/pi/sockets/camcon.sock
    chown-socket = www-data:www-data
    chmod-socket = 777

    uid = www-data
    gid = www-data
uwsgi seems to bind to the socket correctly per the log:
  • uwsgi_config.log
    uwsgi socket 0 bound to TCP address unix:/home/pi/sockets/camcon.sock fd 3
    setgid() to 33
    set additional group 44 (video)
    set additional group 998 (i2c)
    setuid() to 33
The nginx error log indicates that the .py location is being used but fails with a 111 error:
  • 2018/02/06 10:52:00 [debug] 507#507: *1 stream socket 15
    2018/02/06 10:52:00 [debug] 507#507: *1 epoll add connection: fd:15 ev:80002005
    2018/02/06 10:52:00 [debug] 507#507: *1 connect to unix:/home/pi/sockets/camcon.sock, fd:15 #3
    2018/02/06 10:52:00 [error] 507#507: *1 connect() to unix:/home/pi/sockets/camcon.sock failed (111: Connection refused) while connecting to upstream, client: 192.168.1.6, server: localhost, request: "GET /cambot/cgi-bin/index.py HTTP/1.1", upstream: "uwsgi://unix:/home/pi/sockets/camcon.sock:", host: "192.168.1.17"
I have tried placing the socket in /run/uwsgi but the folder disappears on reboot, also in /var/uwsgi all with chown www-data:www-data and chmod 777 -R. With no difference. I don't know what the fd 3 in the uwsgi log and fd:15 in the nginx log refer to but this does seem to be the only difference that may be a clue to the underlying problem. I have trawled the internet for a solution but found nothing that helps. The device is a Pi3 running the latest version of raspian. NGINX & uwsgi were installed a coule of weeks ago.

I am a novice and would be grateful for any help with this frustrating problem.

User avatar
DougieLawson
Posts: 36174
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Problem with unix socket nginx-uwsgi

Tue Feb 06, 2018 11:36 am

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

rjhazeld
Posts: 38
Joined: Mon Feb 16, 2015 9:19 am

Re: Problem with unix socket nginx-uwsgi

Wed Feb 07, 2018 12:21 am

Thanks for the link. I hadn't planned to use Flask. However, I have spent some time this evening re-jigging the setup as described in the article but the end result so far is the same errors. I'll dig into it further later.

rjhazeld
Posts: 38
Joined: Mon Feb 16, 2015 9:19 am

Re: Problem with unix socket nginx-uwsgi

Sun Feb 11, 2018 6:01 pm

Finally cracked the problem. Two issues one uwsgi hadn't fully installed and sockets would not create in/run despite all the ownership and permissions in the app.ini file. However, creating a /var/uwsgi folder owned by www-data and with liberal permissions solved it. Now data being passed from web page to server ok. Next problem getting it into the app in readable form but that is for a different post.

Return to “Python”