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:
- 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;
}
}
- 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.
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?