【问题标题】:Nginx, uwsgi and flask issue with configurationNginx、uwsgi 和烧瓶配置问题
【发布时间】:2020-09-11 22:59:38
【问题描述】:

到目前为止,我有一个在 Ubuntu 18.04 远程服务器上运行 uwsgi 和 nginx 的 Flask 应用程序。这个应用程序由我的网站的一个子域提供服务,监听端口 5002。我想添加一个新的 Flask 应用程序来监听端口 5003,但我一定是做了一些错误的配置,然后一切都崩溃了。现在这两个应用程序都不起作用。

app1 的服务器块

server {
        client_header_buffer_size 64k;
        large_client_header_buffers 4 64k;
        client_max_body_size 75M;
        server_name app.website1.eu;
        location / {
                include uwsgi_params;
                proxy_ignore_client_abort on;
                uwsgi_ignore_client_abort on;
                client_body_buffer_size 64K;
                client_max_body_size 8M;
                uwsgi_pass 127.0.0.1:5002;
                #uwsgi_pass unix:///home/pathto/website1.sock;
                uwsgi_buffer_size 64k;
                uwsgi_buffers 8 64k;
                uwsgi_busy_buffers_size 64k;
                uwsgi_read_timeout 300;
                uwsgi_send_timeout 300;
                uwsgi_connect_timeout 60;
        }
        listen 443 ssl; # managed by Certbot
        listen [::]:443 ssl;
        ssl_certificate /etc/letsencrypt/live/app.website1.eu/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/app.website1.eu/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
        if ($host = app.website1.eu) {
                return 301 https://$host$request_uri;
        } # managed by Certbot
        listen 80;
        listen [::]:80;
        server_name app.website1.eu;
        return 404; # managed by Certbot
}

app2的服务器块

server {
        client_header_buffer_size 64k;
        large_client_header_buffers 4 64k;
        client_max_body_size 75M;
        server_name app.website2.eu;

        location / {
                include uwsgi_params;
                proxy_ignore_client_abort on;
                uwsgi_ignore_client_abort on;
                client_body_buffer_size 64K;
                client_max_body_size 8M;
                uwsgi_pass 127.0.0.1:5003;
                #uwsgi_pass unix:///home/pathto/website2.sock;
                uwsgi_buffer_size 64k;
                uwsgi_buffers 8 64k;
                uwsgi_busy_buffers_size 64k;
                uwsgi_read_timeout 300;
                uwsgi_send_timeout 300;
                uwsgi_connect_timeout 60;
        }

    listen 443 ssl; # managed by Certbot
    listen [::]:443 ssl;
    ssl_certificate /etc/letsencrypt/live/app.website2.eu/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/app.website2.eu/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = app.website2.eu) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
        listen 80;
        listen [::]:80;
        server_name app.website2.eu;
        return 404; # managed by Certbot
}

app1的ini文件

[uwsgi]
module = wsgi:app
master = true
processes = 10
enable-threads = true
uid=ilias
gid=www-data
socket=127.0.0.1:5002
#socket = website1.sock
chmod-socket = 666
vacuum = true
buffer-size=65536
harakiri=60
ignore-sigpipe=true
ignore-write-errors=true
disable-write-exception
post-buffering=1
logger=file:/home/path1/website1/uwsgierror.log
http-keepalive=3000
die-on-term = true

app2的ini文件

[uwsgi]
module = wsgi:app
master = true
processes = 10
enable-threads = true
uid=ilias
gid=www-data
socket=127.0.0.1:5003
#socket = website2.sock
chmod-socket = 666
vacuum = true
buffer-size=65536
harakiri=60
ignore-sigpipe=true
ignore-write-errors=true
disable-write-exception
post-buffering=1
logger=file:/home/path1/website2/uwsgierror.log
http-keepalive=3000
die-on-term = true
  • 我按照DigitalOcean 上的教程进行操作,现在所有应用程序都无法正常工作,因为 nginx 日志中出现的错误是 *10 connect() failed (111: Connection denied),同时连接到上游。
  • 在出现问题之前,我的应用程序在启动时作为 systemd 服务正常启动。现在没有了。
  • python app1.pyuwsgi --socket 0.0.0.0:5002 --protocol=http -w wsgi:app 可以正常运行应用程序
  • 当我尝试添加上游时,我的连接只是超时了。
  • 我使用的是 http 而不是套接字文件。

谁能帮帮我??

【问题讨论】:

    标签: sockets nginx flask ubuntu-18.04 uwsgi


    【解决方案1】:

    与往常一样,这是一个文件夹权限问题。如果您在创建文件夹和创建虚拟环境的步骤中完全按照教程进行操作,那么一切都会顺利进行。

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 1970-01-01
      • 2020-03-04
      • 1970-01-01
      • 2017-08-12
      • 2017-11-16
      • 1970-01-01
      • 2015-05-08
      • 2015-07-18
      相关资源
      最近更新 更多