无法使用 ubuntu、nginx、uwsgi 通过公共 IP 和域连接 flask 应用程序

无法使用 ubuntu、nginx、uwsgi 通过公共 IP 和域连接 flask 应用程序

我是 Web 开发的初学者,尝试使用 ubuntu 18.04、nginx、uwsgi 和 flask 在 oracle 云中部署我的 flask 应用程序。

nginx 配置是默认的。

服务器的 myapp.config 是:

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;
    }
}

现在我正在尝试本地 IP,但是我尝试使用套接字(注释掉 .sock 路径)文件得到了相同的结果。

myapp.ini 是:

[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

我在这里尝试任何方法,无论过去 4 天遇到什么方法我都尝试过,但仍然无法连接。

wsgi.py 是:

from app import app as application

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

我能够使用 wsgi 文件通过以下命令通过 ip 地址访问该应用程序:

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

但是一旦我使用带有命令和服务的 app.ini 文件,就无法访​​问。

myapp 服务是:

[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

请考虑 myapp.service 状态:

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服务状态为:

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.

我希望这两项服务都能正常运行。过去四天我一直在努力解决这个问题,查看了很多博客和教程,内容几乎相同,但仍然无法通过公共 IP 或域连接我的应用程序。

如果我可以提供任何其他详细信息,请告诉我。非常感谢您的帮助,提前谢谢大家 :)

答案1

您应该修复 ini 文件中的这个拼写错误:

socket = 127.0.0.0:5000

该地址应该是 127.0.0.1。

相关内容