Score:0

creating ubuntu service to run a flask app on gunicorn / nginx not working

nr flag

I have loaded a flask app (appserver.py) on ubuntu 20.04 with nginx & gunicorn. This is running on a virtualbox VM on my desktop. I can run the app successfully on a terminal session on ubuntu by running:

gunicorn appserver

I have tried to create a service for this app so that it runs automatically on boot:

  1. created file: /etc/nginx/sites-enabled/appserver
server{  
listen 8001;  
server_name 192.168.68.105;  
location / {  
proxy_pass http://127.0.0.1:8000;  
}  
}  
  1. created the service file: /etc/systemd/system/gunicorn.service
[Unit]  
Description=Gunicorn service  
After=network.target  

[Service]  
User=afshin  
Group=www-data  
WorkingDirectory=/var/www/appserver/appserver  
ExecStart=/usr/bin/gunicorn --workers 3 --bind unix:__init__.sock m 007 __init__  

sudo nginx -t - shows the file format is correct

sudo systemctl daemon-reload

sudo service gunicorn start

sudo service gunicorn status - shows service is active

when I access the site I get 502 Bad Gateway error on the web page.

  • nginx error file shows:
2021/07/11 20:38:41 [error] 3588#3588: *38 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.68.120, server: 192.168.68.105, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: "192.168.68.105:8001", referrer: "http://192.168.68.105:8001/"

I set the ownership for all files in appserver to www-data:www-data - I've tried 777 permissions on all files to get it working but no luck.

What am I doing wrong?

afshin avatar
nr flag
thanks - what are backticks?
Nmath avatar
ng flag
It is a symbol on your keyboard. Use the edit link to review the formatting of this post for an example or search "backtick" in your favorite search engine
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.