移动网络上的HTTP请求408错误(客户端请求超时)。 Django + Gunicorn + Nginx

时间:2017-11-21 22:56:46

标签: django http nginx gunicorn

我遇到了一个奇怪的问题。我的API有端点,我正在使用PATCH(也试过PUT和POST - 相同的结果)从手机发送json与jsonarray(请求体大小通常是40KB)。当我使用Wi-Fi进行此操作时 - 一切正常。但是,如果我使用的是移动网络,我将使用SocketConnection Timeout(在Retrofit / Kotlin中)使用某些手机(iOS工作完美)。

来自nginx access.log:

domain - - [21/Nov/2017:16:33:01 +0000] "PATCH /endpoint/ HTTP/1.1" 408 0 "-" "Dalvik/2.1.0 (Linux; U; Android 6.0.1; Nexus 5 Build/M4B30Z)"

Nginx配置:

server {
    listen port;
    server_name domain;
    client_max_body_size 32m;
    proxy_connect_timeout 75s;
    proxy_read_timeout 300s;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
      root /home/user/apps/api;
    }


     location / {
     include proxy_params;
     proxy_pass http://unix:/home/user/apps/api/api.sock;
}

    listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.com/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

Gunicorn配置:

respawn
setuid root
setgid www-data
chdir /home/user/apps/api

exec /home/user/virtualenvs/apienv/bin/gunicorn --workers 3 --timeout=90 --bind unix://api.sock api.wsgi:application

1 个答案:

答案 0 :(得分:0)

问题出在网络连接上。我们改变了从法兰克福到阿姆斯特丹的云的位置,现在一切都很完美