首页 > 解决方案 > Nginx-ajax-django:页面上出现 504 超时错误,错误日志:上游超时(110:连接超时),TTFB>1

问题描述

我有一个在 nginx 服务器上运行的 django 应用程序,它使用 ajax 对 html 页面进行异步渲染。我收到 504 网关超时错误。我几乎尝试了堆栈溢出中提到的所有解决方案,但没有任何结果。在我的应用程序中,我上传了一个 Excel 表格,从中解析、处理、推送到数据库中的数据,然后在 html 页面上显示处理状态。我意识到前两到三行数据正在正常处理,结果也正在正确显示。对于剩余的行,后端进程正在正确发生,但 ajax 没有从 django 视图接收状态消息。它显示 504 错误消息。错误日志显示上游超时错误。我什至包含timeout:333333在我的 ajax 代码中。如果我做async:false在 ajax 中,进程变慢,我收到页面无响应错误消息。通过仔细观察,我意识到对于不完整的流程,TTFB 正在变得超过 1。那么有人可以解释该怎么做吗?

nginx.conf
events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush off;
        tcp_nodelay on;
        keepalive_timeout 605;
        types_hash_max_size 2048;
        # server_tokens off;
       # proxy_set_header Host $host;
        proxy_http_version 1.1;
        #proxy_set_header Upgrade $http_upgrade;
       # proxy_set_header Connection "upgrade";
        proxy_set_header Connection "";
        proxy_connect_timeout 605;
        proxy_send_timeout 605;
        proxy_read_timeout 605;
        send_timeout 605;
        fastcgi_read_timeout 605;
        client_header_timeout 605;
        client_body_timeout 605;
        proxy_buffering off;
        proxy_request_buffering off;
        # server_names_hash_bucket_size 64;
        # server_name_in_redirect off;
        include fastcgi_params;
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
}

标签: pythondjangoajaxnginxfastcgi

解决方案


推荐阅读