TransWikia.com

Unable to connect flask app by public ip and domain using ubuntu, nginx, uwsgi

Server Fault Asked by Biswajit on December 23, 2021

I am a beginner in web developement, trying to deploy my flask app in oracle cloud with ubuntu 18.04, nginx, uwsgi and flask.

nginx config is default.

myapp.config for server is:

server {
    listen 80;
    listen  [::]:80;
    server_name 152.67.8.6 stag.fick.in www.stag.fick.in;

    location / {
            include uwsgi_params;
            uwsgi_pass 127.0.0.1:5000;
            # unix:/home/ubuntu/FickStaging/fick_backend/fick/fick.sock;
    }
}

Now I am trying local IP but I have tried with socket(commented the .sock path) file got the same result.

myapp.ini is:

[uwsgi]
module = wsgi:application

master = true
processes = 5

socket = 127.0.0.1:5000
#unix:/FickStaging/fick_backend/fick/fick.sock
chmod-socket = 666 #660
vacuum = true

die-on-term = true

Here I am trying anything, whatever I come across from last 4 days tried to use still unable to connect.

wsgi.py is:

from app import app as application

if __name__ == "__main__":
     application.run()

I am able to access the app with ip address using wsgi file with bellow command:

uwsgi --socket 0.0.0.0:5000 --protocol=http -w wsgi

but unable to access once I am using the app.ini file with command also with service.

myapp service is:

[Unit]
Description="uWSGI server instance for fick"
After=network.target

[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/FickStaging/fick_backend/fick
Environment=FLASK_ENV=test
ExecStart=/home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.ini

[Install]
WantedBy=multi-user.target

Please consider the myapp.service status:

fick_staging.service - "uWSGI server instance for fick"
Loaded: loaded (/etc/systemd/system/fick_staging.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-07-24 05:19:40 UTC; 25min ago
Main PID: 32645 (uwsgi)
Tasks: 6 (limit: 1120)
CGroup: /system.slice/fick_staging.service
       ├─32645 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.
       ├─32679 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.
       ├─32680 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.
       ├─32681 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.
       ├─32682 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.
       └─32683 /home/ubuntu/.local/bin/uwsgi --ini /home/ubuntu/FickStaging/fick_backend/fick/app.

 Jul 24 05:19:40 ubuntu uwsgi[32645]: mapped 437424 bytes (427 KB) for 5 cores
 Jul 24 05:19:40 ubuntu uwsgi[32645]: *** Operational MODE: preforking ***
 Jul 24 05:19:41 ubuntu uwsgi[32645]: WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55
 Jul 24 05:19:41 ubuntu uwsgi[32645]: *** uWSGI is running in multiple interpreter mode ***
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI master process (pid: 32645)
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI worker 1 (pid: 32679, cores: 1)
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI worker 2 (pid: 32680, cores: 1)
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI worker 3 (pid: 32681, cores: 1)
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI worker 4 (pid: 32682, cores: 1)
 Jul 24 05:19:41 ubuntu uwsgi[32645]: spawned uWSGI worker 5 (pid: 32683, cores: 1)

nginx service status is:

nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
       └─override.conf
Active: active (running) since Thu 2020-07-23 20:17:51 UTC; 9h ago
 Docs: man:nginx(8)
Process: 27158 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, statu
Process: 27260 ExecStartPost=/bin/sleep 0.1 (code=exited, status=0/SUCCESS)
Process: 27247 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 27234 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 27248 (nginx)
Tasks: 3 (limit: 1120)
CGroup: /system.slice/nginx.service
       ├─27248 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
       ├─27254 nginx: worker process
       └─27255 nginx: worker process

Jul 23 20:17:51 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Jul 23 20:17:51 ubuntu systemd[1]: Started A high performance web server and a reverse proxy server.

I hope both the service are running fine. I am struggling with this from last four days, checked lots of blogs and tutorials with almost same details but still unable to connect my app through public IP or domain.

Please let me know if I can provide any other details. Any help is highly appriciated, thank you all in advance 🙂

One Answer

You should fix this typo in your ini file:

socket = 127.0.0.0:5000

The address should have been 127.0.0.1.

Answered by Michael Hampton on December 23, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP