502 Bad Gateway - no tmp/web2py.socket file

664 views
Skip to first unread message

Richard Brown

unread,
Nov 22, 2016, 12:34:40 PM11/22/16
to web2py-users
I've just tried to do a new install of Web2py on a Raspberry Pi 3 having been using it under Apache on a Model B for a few years now. I used the script "setup-web2py-nginx-uwsgi-ubuntu.sh" which seems to have done most things correctly, but when I try to access the site I get a '502 Bad Gateway' error in my browser and the following error in /var/log/nginx/error.log:

2016/11/22 16:41:30 [crit] 648#0: *1 connect() to unix:///tmp/web2py.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.65, server: raspberrypi, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/web2py.socket:", host: "192.168.1.60"

There is no web2py.socket file in the /tmp directory or anywhere else that I can find. I can see where the script sets up the path to this file but nothing about how the file itself should get there. Where do I find this file, or should the configuration point to a different file?

Thanks,

Richard

Niphlod

unread,
Nov 22, 2016, 2:19:25 PM11/22/16
to web2py-users
that should be generated by the uwsgi daemon

Richard Brown

unread,
Nov 22, 2016, 5:19:32 PM11/22/16
to web2py-users
Thanks for the reply. The key word here is obviously 'should' - but is it something that should have happened or something I should have done, and how do I resolve it? I used the 'one step deployment' script as thought it would do everything I need to get Web2py working.

Richard

Niphlod

unread,
Nov 23, 2016, 3:54:43 AM11/23/16
to web2py-users
one step deployment imho is not "assured to be working" on raspberry. 
easy check: do you have an uwsgi process running ?

Richard Brown

unread,
Nov 23, 2016, 5:47:26 AM11/23/16
to web2py-users
Not such an easy check - how do I do that? Also, what is the 'uswgi daemon'?

Perhaps I'm asking the wrong question. I've developed a Web2py application for Home Heating Control and a suite of radio linked hardware to make it work. I'm a hardware/embedded software engineer by profession with no previous knowledge of Linux, but I've managed to pick up enough knowledge to navigate around, run commands, edit files, start processes automatically at start up etc,, but only if I'm given the actual command to run or the exact lines to add to a configuration file.

I would like to make my Heating application available to others, so wanted to start with a new Raspberry Pi, go through the steps to get it running for myself but also documenting the steps to pass on to potential users. Obviously this has gone off the rails at a very early stage and I don't know how to fix it. The people who would potentially be wanting to use my application will be hobbyists, buying their first Pi, installing Web2py to run from a browser on  remote PC, downloading my application and using it. They will not have, and should not need have to have any in-depth knowledge of Linux to do this. If the 'one step' script doesn't work, where do I find a bulletproof procedure that works?

I also tried the procedure given in:

...although it still assumes that I know what 'server_domain_or_IP' and 'myapp' should be, which I don't. Anyway I guessed and everything worked apart from the last step 'sudo service uwsgi start' which failed with the message:
Failed to start uwsgi.service: Unit uwsgi.service failed to load: No such file or directory. Probably points to the same issue, but still offers me no clue how to resolve it.

Niphlod

unread,
Nov 23, 2016, 6:54:21 AM11/23/16
to web2py-users
ok, let's break it down.
The script basically does:
- install and configure nginx
- install and configure uwsgi

uwsgi is the process that takes care of executing any python code (meaning, your webapp) .
nginx is the process that takes care of receiving an http request, passing it down to uwsgi, get the results and send the http response back to your browser.
Both need to be running in order for your app to work.

In order to let the two communicate, nginx expects a "file" (/tmp/web2py.socket) . That file is created by uwsgi.
It's possible that one of the steps of the script didn't work out, hence your error.
The error you posted seems to point out that nginx is configured correctly, but for some reason uwsgi is not.

The first thing to check is that you have the uwsgi daemon.
There's a command, "which", that will tell you the location of any executable is ready on your system.
So, type  "which uwsgi" in a terminal to know if at least it got installed. it should reply "/usr/local/bin/uwsgi"

If it's installed, the next check is see if it's configured correctly.
Systemd is used to let uwsgi start:
- Check if you have a file at /etc/systemd/system/emperor.uwsgi.service
An ini file is responsible to let uwsgi know WHAT to run:
- Check if you have a file at /etc/uwsgi/web2py.ini

If all of the above checks out, we'll need further steps, but for the time being check them 


Richard Brown

unread,
Nov 23, 2016, 7:36:35 AM11/23/16
to web2py-users
Thanks, the answer is 'yes' to all of these checks - web2py.ini file attached. I did find out how to see if the uwsgi process is running and it does appear to be:

 $ ps aux | grep "uwsgi"
richard   1044  0.0  0.1   4276  1824 pts/0    S+   10:54   0:00 grep --color=auto uwsgi
web2py.ini

Niphlod

unread,
Nov 23, 2016, 8:14:00 AM11/23/16
to web2py-users
okay, you can see in the first line that /tmp/web2py.socket is mentioned.

if uwsgi is running, need to check the log to see if any errors comes up

check in /var/log/uwsgi and/or see if systemd logging reports something with "journalctl /usr/local/bin/uwsgi"

Richard Brown

unread,
Nov 23, 2016, 8:27:20 AM11/23/16
to web2py-users
Hi, there are no files in '/var/log/uwsgi' and  "journalctl /usr/local/bin/uwsgi" reports "No journal files were found."

Niphlod

unread,
Nov 23, 2016, 1:03:55 PM11/23/16
to web2py-users
okay, now we have a deal ^_^ ...

what about 

journalctl -u emperor.uwsgi.service

?

Richard Brown

unread,
Nov 23, 2016, 2:52:44 PM11/23/16
to web2py-users
Still the same response - "No journal files were found."

A couple of further questions:

1. Out of interest - should the /tmp/web2py.sock file be installed during installation, or each time uwsgi runs?
2. Am I correct in just pointing my PC browser at the IP address of my Raspberry Pi (htpps://192.168.1.60) as I do with the Apache method and expecting to find the Web2py welcome page?

In parallel with this I started from scratch with another SD Card and ran the Apache/mod_wsgi/Web2py/PostgreSQL script (once I located it in the repository) and it worked first time - straight into Web2py. Why is nginx/uwsgi now preferred and what advantages does it offer in my application?

Johann Spies

unread,
Nov 24, 2016, 4:55:21 AM11/24/16
to web...@googlegroups.com
On 23 November 2016 at 14:36, Richard Brown <rab...@gmail.com> wrote:
Thanks, the answer is 'yes' to all of these checks - web2py.ini file attached. I did find out how to see if the uwsgi process is running and it does appear to be:

 $ ps aux | grep "uwsgi"
richard   1044  0.0  0.1   4276  1824 pts/0    S+   10:54   0:00 grep --color=auto uwsgi


No it seems it is not running.  Your result showed the grep of uwsgi.

Try

ps aux | grep [u]wsgi

This will not show your grep command.

Regards
Johann
--
Because experiencing your loyal love is better than life itself,
my lips will praise you.  (Psalm 63:3)

Richard Brown

unread,
Nov 24, 2016, 11:09:35 AM11/24/16
to web2py-users
Hi Johann,

I wasn't sure whether the [u] was to be included or indicated an option with or without the 'u', so I tried all three. Results below:

richard@raspberrypi:~ $ ps aux | grep [u]wsgi
richard@raspberrypi:~ $ ps aux | grep wsgi
richard   1017  0.0  0.1   4276  1852 pts/0    S+   16:02   0:00 grep --color=auto wsgi
richard@raspberrypi:~ $ ps aux | grep uwsgi
richard   1019  0.0  0.2   4276  2016 pts/0    S+   16:02   0:00 grep --color=auto uwsgi
richard@raspberrypi:~ $

Richard

Jim Russell

unread,
Nov 25, 2016, 11:11:41 PM11/25/16
to web2py-users


 $ ps aux | grep "uwsgi"
richard   1044  0.0  0.1   4276  1824 pts/0    S+   10:54   0:00 grep --color=auto uwsgi

That is the grep process, not uwsgi.  So uwsgi is not running.

Check in /var/log/nginx/ for any messages about uwsgi 

Richard Brown

unread,
Nov 28, 2016, 5:20:05 AM11/28/16
to web2py-users
The only message is still:

2016/11/28 10:17:55 [crit] 674#0: *1 connect() to unix:///tmp/web2py.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.65, server: raspberrypi, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///tmp/web2py.socket:", host: "192.168.1.60"

Ari Lion BR Sp

unread,
May 4, 2017, 3:47:49 PM5/4/17
to web2py-users
I have the exact same problem. Some resulution?
(Running in Virtualbox (Host Windows7 Pro / Guest Ubuntu-64) , NAT => Ports redirection (8080 Host / 80 Guest))
Reply all
Reply to author
Forward
0 new messages