My hopes are lost and so is my temper. I have followed the tutorial found here - https://www.digitalocean.com/community/tutorials/how-to-serve-flask-applications-with-uwsgi-and-nginx-on-ubuntu-16-04
I have reinstalled and started all over 10 times and still same PROBLEM. Is there another tutorial available because this only works to 80%. All works fine up to a certain point but I always get a 502 gateway problem.
I created a new user belonging to sudo group. Ssh:ed to server with this new user – all good. Set up domain also and if I ping domainname.com the correct droplet ip gives reply – all good.
python myproject.py (to start flask) works perfect
uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi:app
Works perfect and site is accessible with IP http://server_IP:5000
Content of wsgi.py-
from myproject import app
if name == “_main”: app.run()
Content of myproject.ini looks like -
[uwsgi]
module = wsgi:app
master = true processes = 5
socket = myproject.sock chmod-socket = 660 vacuum = true
die-on-term = true
Content of /etc/systemd/system/myproject.service:
[Unit] Description=uWSGI instance to serve myproject After=network.target
[Service] User = blizzard Group = www-data WorkingDirectory = /home/blizzard/myproject Environment = “PATH=/home/blizzard/myproject/myprojectenv/bin” #IS THIS LINE WRONG?? ExecStart=/home/blizzard/myprojectenv/bin/uwsgi --ini myproject.ini
[Install] WantedBy = multi-user.target
Content of /etc/nginx/available-sites/myproject
server { listen 80; server_name billigaflygtilllondon.com www.billigaflygtilllondon.com;
location / {
include uwsgi_params;
uwsgi_pass unix:///home/blizzard/myproject/myproject.sock;
}
}
If this tutorial is wrong why dont staff delete it or at least the author updates it since I am not the ONLY ONE having problems. If there is a helpful soul who could guide me I would be more than happy.
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!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
@broodforge
Here’s what I did, step-by-step, on a test Droplet with Ubuntu 16.04 64bit.
Update, Upgrade, Install
Create New User + Directories
Setup VirtualEnv
Source Env File
Install Flask and UWSGI
Create Project File
Within it, I pasted:
Testing myproject.py
I see the Hello There as I should, so let’s move on…
Create the WSGI Entry Point
Within it, I pasted:
Testing UWSGI
I see the Hello Three as I should, so let’s move on.
Deactivate
Creating a uWSGI Configuration File
Within it, I pasted:
Creating systemd Service File
Within it, I pasted:
Setting Proper Permissions
Add
sammy
towww-data
group:Starting and Enabling the Service
Setting Up NGINX
Within it, I pasted:
Created a symlink using:
Restart NGINX:
…
For this particular setup, passing
--uid
and--gid
isn’t required andsystemctl
does handle the user and group permissions correctly.I just want to Thank You for this post and to all who helped solve these issues. It really helped me out BIG TIME. I like you was stuck and very frustrated, but this thread was a godsend.
@broodforge
Starting a new reply as the other was at its max.
You could very well use the same user and group, though from a security standpoint, it’s not the best method. Ideally, each project should run as an individual user (that isn’t
root
or asudo
user).