Nginx + uWSGI错误的网关

时间:2018-12-19 18:12:11

标签: nginx

我用Python Pyramid制作了一个应用程序,并使用Nginx部署到Ubuntu 18.04服务器上,并且工作正常,但是其中一个端点处理繁重。用户上传一个excel,对于excel的每一行,我都会在Google上获取GPS坐标并进行一些验证。然后,我的API会对每行进行反馈。

即使需要很长时间,我也确实需要给用户该响应。仅在此端点中,当要处理的文件有很多行时,我的API会引发错误502。我一直在尝试在StackOverflow上看到的所有类似问题的答案,但到目前为止都无济于事。

这是我的服务

Description=uWSGI Snow Server server instance
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --ini-paste /webapps/<app folder>/production.ini
# Requires systemd version 211 or newer
RuntimeDirectory=/webapps/<app folder>/
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all

[Install]
WantedBy=multi-user.target

这是我的Nginx配置:

server {
    listen 80 default_server;
    server_name dev.anything.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name dev.anything.com;
    server_tokens off;

    ssl_certificate /etc/letsencrypt/live/dev.anything.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.anything.com/privkey.pem;

    charset utf-8;
    client_max_body_size 1M;

    location /static {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        alias /webapps/<app folder>/pyramid_rest_api/static;
        expires 1d;
    }
    location / {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;
        uwsgi_read_timeout 500;
        try_files $uri @yourapplication;
    }

    location @yourapplication {
        gzip            on;
        gzip_buffers    8 256k;
        uwsgi_buffers   8 256k;

        server_tokens off;
        include uwsgi_params;
        proxy_connect_timeout   500;
        proxy_send_timeout      500;
        proxy_read_timeout      500;
        send_timeout    500;
        proxy_set_header Host $host;
        proxy_set_header real_scheme $scheme;
        proxy_set_header X-Forwarded-Protocol $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://127.0.0.1:8999;
    }
}

以及我的.ini文件的内容:

[uwsgi]
http = 127.0.0.1:8999
chdir=/webapps/<app folder>/pyramid_rest_api/
master = true
processes = 10
enable-threads = true

harakiri = 60
harakiri-verbose = true
limit-post = 65536
post-buffering = 8192

logto = /webapps/logs/snow_service/uwsgi.log
log-slow = true
need-app = true

我可以做些调整来使此错误停止吗?

0 个答案:

没有答案