nginx设置超时时间的问题及解决方案,


目录
  • nginx设置超时时间
    • 前言:
  • nginx出现504 Gateway Time-out
    • 问题
    • 解决方法

nginx设置超时时间

前言:

    nginx默认请求时间是60s,在特殊的情况下个别的请求时间会超过60秒,比如在进行复杂的硬件操作或重复多
次的硬件操作的时候,就会超过60s,超时会报错。
    通过配置nginx配置文件可以修改默认的超时时间:

nginx配置:(以下配置文件经过脱敏,拿自己想要的即可)

server {
        listen       *:65531;
        server_name  0.0.0.0;
        error_log   stderr warn;
        access_log  stdout main;
        proxy_send_timeout 180s;     # 设置发送超时时间,
        proxy_read_timeout 180s;	 # 设置读取超时时间。
        location ^~/apig/ {
          client_max_body_size                    "100m";
          proxy_pass https://localhost:8086/;
        }
        location / {
            root   /opt/ty/console;
            index  index.html index.htm;
        }
        location = /index.html {
            root   /opt/ty/console;
            index  index.html index.htm;
            add_header Cache-Control "no-cache, no-store";
        }
        error_page  404              /;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

nginx出现504 Gateway Time-out

问题

nginx访问出现504 Gateway Time-out

常见原因:程序在处理大量数据,接口超过1分钟(默认的)未返回数据,导致等待超时。

出现这种情况,我们可以先优化程序,缩短执行时间。可以调大nginx超时限制的参数,使程序可以正常执行。

解决方法

nginx配置nginx.conf中,设置以下几个参数,增加超时时间配置:

如果使用了Nginx的代理,可以在下面这里加上下面三个配置:

location /foo {
     proxy_pass http://xxx.xxx.xxx.xxx:8080/foo;
     proxy_connect_timeout      300s;       # 默认60s
     proxy_send_timeout           300s;       # 默认60s
     proxy_read_timeout           300s;       # 默认60s
}

到此这篇关于nginx设置超时时间的文章就介绍到这了,更多相关nginx设置超时时间内容请搜索PHP之友以前的文章或继续浏览下面的相关文章希望大家以后多多支持PHP之友!

您可能感兴趣的文章:
  • 详解Nginx服务器中配置超时时间的方法
  • 详解Nginx的超时keeplive_timeout配置步骤
  • Nginx timeout超时配置详解
  • Nginx的超时timeout配置详解
  • Nginx 上传大文件超时解决办法

相关内容