nginx設置超時時間的問題及解決方案
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; # 設置發(fā)送超時時間,
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分鐘(默認的)未返回數據,導致等待超時。
出現這種情況,我們可以先優(yōu)化程序,縮短執(zhí)行時間。可以調大nginx超時限制的參數,使程序可以正常執(zhí)行。
解決方法
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設置超時時間內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Nginx安裝lua-nginx-module模塊的方法步驟
ngx_lua_module 是一個nginx http模塊,這篇文章主要介紹了Nginx安裝lua-nginx-module模塊的方法步驟,非常具有實用價值,需要的朋友可以參考下2018-12-12

