Reputation: 7077
I followed these 2 articles: Article 1, Article 2 to setup my Python Fast API project.
Followed these 2 articles, I installed Gunicorn and Ngnix on the VM from Oracle Cloud.
Here are my configuration files:
/etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=ubuntu
Group=ubuntu
WorkingDirectory=/home/ubuntu/maze
ExecStart=/home/ubuntu/.local/bin/gunicorn \
--access-logfile - \
--workers 4 \
-k uvicorn.workers.UvicornWorker \
-b unix:gunicorn.sock \
-m 007 \
--timeout 1200 \
main:app
[Install]
WantedBy=multi-user.target
/etc/nginx/conf.d/gunicorn.conf
server {
listen 8000;
server_name 168.138.12.192;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://unix:/run/gunicorn.sock;
}
}
/etc/systemd/system/gunicorn.socket
[Unit]
Description=gunicorn socket
[Socket]
ListenStream=/run/gunicorn.sock
[Install]
WantedBy=sockets.target
then I ran the following commands, to make sure the changes take effective
sudo systemctl daemon-reload
sudo systemctl restart gunicorn
sudo systemctl restart gunicorn.service
sudo systemctl restart gunicorn.socket
sudo systemctl restart nginx
sudo systemctl enable gunicorn
sudo systemctl enable gunicorn.service
sudo systemctl enable gunicorn.socket
sudo systemctl enable nginx
Also ran
sudo systemctl status gunicorn.service
to make sure the service is up and running. It looks good to me:
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Sun 2021-05-23 02:47:59 UTC; 10s ago
TriggeredBy: ● gunicorn.socket
Main PID: 4142 (gunicorn)
Tasks: 13 (limit: 1107)
Memory: 339.2M
CGroup: /system.slice/gunicorn.service
├─4142 /usr/bin/python3 /home/ubuntu/.local/bin/gunicorn --access-logfile - --workers 4 -k uvicorn.workers.UvicornWorker -b unix:/run/gunicorn.sock -m 007 --timeout 1200 m>
├─4153 /usr/bin/python3 /home/ubuntu/.local/bin/gunicorn --access-logfile - --workers 4 -k uvicorn.workers.UvicornWorker -b unix:/run/gunicorn.sock -m 007 --timeout 1200 m>
├─4154 /usr/bin/python3 /home/ubuntu/.local/bin/gunicorn --access-logfile - --workers 4 -k uvicorn.workers.UvicornWorker -b unix:/run/gunicorn.sock -m 007 --timeout 1200 m>
├─4157 /usr/bin/python3 /home/ubuntu/.local/bin/gunicorn --access-logfile - --workers 4 -k uvicorn.workers.UvicornWorker -b unix:/run/gunicorn.sock -m 007 --timeout 1200 m>
└─4159 /usr/bin/python3 /home/ubuntu/.local/bin/gunicorn --access-logfile - --workers 4 -k uvicorn.workers.UvicornWorker -b unix:/run/gunicorn.sock -m 007 --timeout 1200 m>
May 23 02:48:08 instance-20210520-2215 gunicorn[4154]: [2021-05-23 02:48:08 +0000] [4154] [INFO] Application startup complete.
May 23 02:48:08 instance-20210520-2215 gunicorn[4157]: [2021-05-23 02:48:08 +0000] [4157] [INFO] Started server process [4157]
May 23 02:48:08 instance-20210520-2215 gunicorn[4157]: [2021-05-23 02:48:08 +0000] [4157] [INFO] Waiting for application startup.
May 23 02:48:08 instance-20210520-2215 gunicorn[4157]: [2021-05-23 02:48:08 +0000] [4157] [INFO] Application startup complete.
May 23 02:48:08 instance-20210520-2215 gunicorn[4153]: [2021-05-23 02:48:08 +0000] [4153] [INFO] Started server process [4153]
May 23 02:48:08 instance-20210520-2215 gunicorn[4153]: [2021-05-23 02:48:08 +0000] [4153] [INFO] Waiting for application startup.
May 23 02:48:08 instance-20210520-2215 gunicorn[4153]: [2021-05-23 02:48:08 +0000] [4153] [INFO] Application startup complete.
May 23 02:48:08 instance-20210520-2215 gunicorn[4159]: [2021-05-23 02:48:08 +0000] [4159] [INFO] Started server process [4159]
May 23 02:48:08 instance-20210520-2215 gunicorn[4159]: [2021-05-23 02:48:08 +0000] [4159] [INFO] Waiting for application startup.
May 23 02:48:08 instance-20210520-2215 gunicorn[4159]: [2021-05-23 02:48:08 +0000] [4159] [INFO] Application startup complete.
then I ran this command to see whether I am able to see the correct website on the VM
curl http://localhost:8000
I did see my website got returned.
BUT, when I try to access the website from my browser by the following IP addresses:
http://http://168.138.12.192/
I can see the default nginx website
http://168.138.12.192:8000/
Firefox shows me Unable to connect
What am I missing??
Upvotes: 0
Views: 2089
Reputation: 7077
It turns out that I need to also alter the firewall rule to open port 8000, although I have added the Ingress rule to pen port 8000
sudo iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 8000 -j ACCEPT
Upvotes: 1