Repository navigation
nginx and uwsgi deployment #35
Description
Hi there,
I'm wondering if the process of serving the app via nginx/uwsgi has been documented anywhere? I know there's a quick start run through on httpd. I've been trying for a few days on and off and I can't even seem to get it to serve directly from the uwsgi server. Via nginx I get 502 socket file cannot be created. And via uwsgi I just get internal server error.
It's likely I'm doing something dumb but is the app set up to just plugin the uwsgi.ini into the server as long as it's pointing to the .wsgi file and the projectdir? It's a flask based app correct? I've run through a bit of the documentation and I should be able to serve it at a bear minimum with uwsgi.
I can run it fine with the ceph-dash.py file so all dependencies are met and the likes.
Any help or tuts you can direct me to that apply to the structure of this app and how it should be served sort of like a step by step so's I know I'm not fecking it up.
Trying to start with uwsgi:
uwsgi --http :5000 --chdir /etc/nginx/sites-enabled/ceph-dash/ --wsgi-file /etc/nginx/sites-enabled/ceph-dash/cephdash.wsgi --callable application --master --uid nginx --gid nginx
Server starts:
As you can see I added print statements to sys.path and application within the .wsgi to check it was loading and it finds what it needs apparently. But mountpoint is still empty.
*** Operational MODE: single process *** ['/etc/nginx/sites-enabled/ceph-dash/app/', '.', '', '/usr/lib64/python27.zip', '/usr/lib64/python2.7', '/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk', '/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7/site-packages', '/usr/lib/python2.7/site-packages'] <Flask 'app'> WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xe0b6d0 pid: 26487 (default app) *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 26487, cores: 1)
Request gives internal server error:
[pid: 26487|app: 0|req: 1/1] 10.0.2.2 () {36 vars in 614 bytes} [Sun Aug 28 11:07:06 2016] GET / => generated 291 bytes in 49 msecs (HTTP/1.1 500) 2 headers in 84 bytes (1 switches on core 0)
Also tried with the .ini file:
uwsgi --ini uwsgi.ini
chdir = /etc/nginx/sites-enabled/ceph-dash
wsgi-file = /etc/nginx/sites-enabled/ceph-dash/cephdash.wsgi
enable-threads = true
master = true
processes = 4
#socket = /var/run/ceph-dash.socket
http = :5000
#chmod-socket = 664
vacuum = true
uid = nginx
gid = nginx
daemonize = /var/log/uwsgi/ceph-dash.log
What am I doing wrong? Pretty sure it's going to come down to either wrong file in wrong place or uwsgi not pointing to the correct place.
Cheers
Activity
Crapworks commentedon Aug 28, 2016
Hi @Lighiche
to be honest, I was never running ceph-dash with nginx, only with apache. So I can't really point in the right direction. The error message also doesn't tell me much about what could be wrong.
To answer your question: Yes, it's a flask based app and should work with any wsgi capable webserver.
Are there any other logfiles or error messae that could hint on the problem?
Were you using the wsgi file provided under
ceph-dash/contrib/wsgi/cephdash.wsgi? Because in the ini file you point toceph-dash/cephdash.wsgi.If you've copied the file from the contrib folder from to the toplevel dir, you need to change the line.
to
Regards,
Christian
ac-obair commentedon Aug 29, 2016
Hi there, thanks for the reply. This is absolutely everything I have and everything I know to try.
I copied files out of the contrib folder to:
/opt/ceph-dash/
I've changed the lines slightly to reflect that I had moved the
.wsgiconfig file up to a higher level I've since moved it back tocontrib/wsgi/cephdash.wsgiand it's the same issue.I have the cloned dir in this folder
/etc/nginx/sites-enabled/ceph-dash/The only other error log I get is when I place nginx infront of uwsgi, I blanked out the hostname not that it really matters.
2016/08/29 09:58:17 [crit] 29117#0: *3 connect() to unix:///var/run/ceph-dash.sock failed (2: No such file or directory) while connecting to upstream, client: 127.0.0.1, server: <hostname>, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///var/run/ceph-dash.sock:", host: "localhost:5000"I already have nginx on these boxes serving something for me and there's a whole HA load balancing thing going on a step above on the network so I'd prefer not to then complicate it more with apache ya know. If I write a small helloworld flask app, I can serve that via flask and uwsgi
with flask:
127.0.0.1 - - [29/Aug/2016 10:13:30] "GET / HTTP/1.1" 200 -
with uwsgi:
uwsgi --http :5000 --wsgi-file hellworld.py --callable app --processes 4 --threads 2 --stats 127.0.0.1:9191
I've even
tried using
--http-socketin uwsgi and changing the upsteam in nginx to be a listening portcephdash.conf
uwsgi.ini
http-socket = :3000nginx error.log
2016/08/29 10:39:25 [error] 29489#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 127.0.0.1, server: prdceph-mon00, request: "GET / HTTP/1.1", upstream: "uwsgi://0.0.0.0:3000", host: "localhost:5000"Response is still
502bad gateway. At this point it's obvious to me that uwsgi can't serve the app I just can't figure out why.So
For clarity AS ROOT starting with
uwsgi --ini uwsgi.iniOn port 3000 I get
And the only log output for this is:
bllacksheep commentedon Aug 31, 2016
Running wsgi with nginx for dummies
So ever wanted to know how to fix all the problems?
FIX FOR 500 RESPONSE CODE
Nginx is NOT starting any wsgi processes for you, I had to start this server manually. In order to get this to work from uwsgi the full path MUST be given to .wsgi file.
All files owned by nginx in /etc/nginx/sites-enabled
WORKING
uwsgi server doing the http business
uwsgi --socket 0.0.0.0:5000 --protocol=http --wsgi-file /etc/nginx/sites-enabled/ceph-dash/contrib/wsgi/cephdash.wsgiWORKING
uwsgi --ini uwsgi.iniFIX FOR BAD GATEWAY 502 Bad Gateway (nginx can't find uwsgi server)
start the uwsgi server and make sure the next fix 503 is in place
FIX FOR BAD GATEWAY 503 (uwsgi server reachable but not able to process request)
The point of wsgi protocol (natively supported by nginx) is that it can proxy_pass requests off to the uwsgi server, ** in a wsgi binary format ** the http is handled by the listening nginx port 5000.
WORKING
uwsgi --ini uwsgi.iniNow start nginx with this config
The response for this is successful
FIX FOR USING .SOCK FILE
If uwsgi can't create the socket the server won't start. You can quickly find out if it started with
pgrep uwsgi. If it returns nothing then it's not running you can also check manually if the socket created.NOTES
socket = /tmp/ceph-dash.sockhowever programs starting a socket in /tmp can only be seen by the program that created it. So nginx can't connect to it.cephuser. Now uwsgi could create it but nginx still couldn't access it to pass to because it now does not have permission. To get around this I just set the chmod-socket permissions to 777 and restarted uwsgi, it worked.It's not ideal and there's probably a better way to either host that server with the same user running wsgi or have a group with shared membership access.
WORKING
And comfirmation:
Finally change the nginx upsteam block and restart nginx and voilà, pay dirt.
Crapworks commentedon Jan 7, 2017
Hi @Lighiche
thank you for the detailed solution! Is this problem fixed for you and can I close this issue? I would also like to create a FAQ section in the README and link to this issue so that people who have the same problems can easily find it. Ok for you?
Regards,
Christian
bllacksheep commentedon Jan 29, 2017
Crapworks commentedon Jan 30, 2017
Hi,
thanks!
https://github.com/Crapworks/ceph-dash#user-content-faq
Regards,
Christian