By rbourne
I start this off with the fact that I am a python developer and I know very little about server management so this is all a learning curve for me.
I created a new Ubuntu 16.04 droplet and I followed this tutorial - https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-gunicorn-and-nginx-on-ubuntu-16-04. All was well and it worked.
I used Filezilla to move my flask application from my localhost to the droplet. I overwrote the old app.py with my app.py. wsgi.py was unchanged nothing else should have changed.
I ran sudo systemctl restart myproject and went to view the server from my browser and I received a 502 error.
Looking at the error log I have this:
2017/01/29 23:21:37 [crit] 18456#18456: *1 connect() to unix:/home/user/myproj/proj.sock failed (2: No such file or directory) while connecting to upstream, client: xx.xx.xx.xx, server: xx.xx.xx.xx, request: “GET / HTTP/1.1”, upstream: “http://unix:/home/user/myproj/proj.sock:/”, host: “xx.xx.xx.xx”
Which suggests there’s no socket file. I ran ls -al in /home/user/myproj and I can verify it’s not there. I didn’t delete it so I am not sure what happened to it and how to make it return.
I’ve verified the nginx.conf in /sites-enabled for this project and in the systemctl .service and all the info matches up.
I tried restarting/reloading my project.service, nginx and even a reboot of the server and no luck.
How do I properly return this socket file?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
I was following the same tutorial when myproject.sock disappeared. I am using supervisor so in myproject.ini, i set socket=127.0.0.1:8080 an then cd /etc/nginx/sites-available, edit the myproject file. In location,
location / { include uwsgi_params; uwsgi_pass 127.0.0.1:8080; }
Then you need to restart nginx and it should work fine
I found the solution.
My uploaded app.py was not able to be compiled on the server due to having not (yet) installed the requirements. I used pip install from my requirements.txt, verified I could run python app.py and when it was good to go I restarted myproject.service and the socket file was created. I could then view the app on the internet.
http://unix:/home/user/myproj/proj.sock:/
At first glance, the above is the key indicator. Sockets aren’t accessed over http locally, and that line seems to state that it’s attempting to do so – when it does, it fails.
Socket connects should look like:
unix:/home/user/myproj/proj.sock
So you’d need to find the line where the http:// is being defined and remove that.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.