日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

nginx mysql设置远程连接超时_nginx中的超时设置

發布時間:2025/3/12 数据库 65 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx mysql设置远程连接超时_nginx中的超时设置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

nginx使用proxy模塊時,默認的讀取超時時間是60s。

1. send_timeout

syntax:?send_timeout the time

default:?send_timeout 60

context:?http, server, location

Directive assigns response timeout to client. Timeout is established not on entire transfer of answer, but only between two operations of reading, if after this time client will take nothing, then nginx is shutting down the connection.

2. 負載均衡配置時的2個參數:fail_timeout和max_fails

這2個參數一起配合,來控制nginx怎樣認為upstream中的某個server是失效的當在fail_timeout的時間內,某個server連接失敗了max_fails次,則nginx會認為該server不工作了。同時,在接下來的 fail_timeout時間內,nginx不再將請求分發給失效的server。

個人認為,nginx不應該把這2個時間用同一個參數fail_timeout來控制,要是能再增加一個fail_time,來控制接下來的多長時間內,不再使用down掉的server就更好了~

如果不設置這2個參數,fail_timeout默認為10s,max_fails默認為1。就是說,只要某個server失效一次,則在接下來的10s內,就不會分發請求到該server上

3. proxy模塊的 proxy_connect_timeout

syntax:?proxy_connect_timeout timeout_in_seconds

context:?http, server, location

This directive assigns a timeout for the connection to the proxyserver. This is not the time until the server returns the pages, this is the proxy_read_timeout statement. If your proxyserver is up, but hanging (e.g. it does not have enough threads to process your request so it puts you in the pool of connections to deal with later), then this statement will not help as the connection to the server has been made. It is necessary to keep in mind that this time out cannot be more than 75 seconds.

4. proxy模塊的proxy_read_timeout

syntax:?proxy_read_timeout the_time

default:?proxy_read_timeout 60

context:?http, server, location

This directive sets the read timeout for the response of the proxied server. It determines how long NGINX will wait to get the response to a request. The timeout is established not for entire response, but only between two operations of reading.

In contrast to proxy_connect_timeout, this timeout will catch a server that puts you in it's connection pool but does not respond to you with anything beyond that. Be careful though not to set this too low, as your proxy server might take a longer time to respond to requests on purpose (e.g. when serving you a report page that takes some time to compute). You are able though to have a different setting per location, which enables you to have a higher proxy_read_timeout for the report page's location.

If the proxied server nothing will communicate after this time, then nginx is shut connection.

另一個參考:504 Gateway Time-out問題

常見于使用nginx作為web server的服務器的網站

我遇到這個問題是在升級discuz論壇的時候遇到的

一般看來, 這種情況可能是由于nginx默認的fastcgi進程響應的緩沖區太小造成的, 這將導致fastcgi進程被掛起, 如果你的fastcgi服務對這個掛起處理的不好, 那么最后就極有可能導致504 Gateway Time-out

現在的網站, 尤其某些論壇有大量的回復和很多內容的, 一個頁面甚至有幾百K

默認的fastcgi進程響應的緩沖區是8K, 我們可以設置大點

在nginx.conf里, 加入:

fastcgi_buffers 8 128k

這表示設置fastcgi緩沖區為8×128k

當然如果您在進行某一項即時的操作, 可能需要nginx的超時參數調大點, 例如設置成60秒:

send_timeout 60;

調整了這兩個參數, 結果就是沒有再顯示那個超時, 可以說效果不錯, 但是也可能是由于其他的原因, 目前關于nginx的資料不是很多, 很多事情都需要長期的經驗累計才有結果。

proxy_redirect off;

proxy_set_header Host$host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 10m;

client_body_buffer_size 128k;

proxy_connect_timeout90;

proxy_send_timeout90;

proxy_read_timeout90;

proxy_buffer_size 4k;

proxy_buffers324k;

proxy_busy_buffers_size 64k;

由于審標時間長 ?nginx 配置如下:

user nginx;

worker_processes12;

worker_rlimit_nofile102400;

error_log/var/log/nginx/error.log warn;

pid/var/run/nginx.pid;

events {

use epoll;

worker_connections102400;

}

http {

include/etc/nginx/mime.types;

default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request"'

'$status $body_bytes_sent "$http_referer"'

'"$http_user_agent" "$http_x_forwarded_for"';

access_log/var/log/nginx/access.log main;

sendfile on;#tcp_nopush on;

keepalive_timeout2048;

send_timeout2048;

fastcgi_connect_timeout2048;#gzip on;

include/etc/nginx/conf.d/*.conf;#設定負載均衡的服務器列表

upstream myServer {#weigth參數表示權值,權值越高被分配到的幾率越大

#本機上的apache開8080端口

server 127.0.0.1:8080;#server 192.168.1.101:80 weight=4 max_fails=2 fail_timeout=25s;

#ip_hash;

}

server {

listen80;

server_name xxx.com;

server_name 1xxx.com;

server_name xx.xx.xx.xx;

location ~ ^/NginxStatus/{

stub_status on;

access_log off;

}

location/{

proxy_pass http://myServer;

proxy_redirect off;

proxy_set_header Host$host;

proxy_set_header X-Real-IP $remote_addr;#proxy_set_header REMOTE-HOST $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

client_max_body_size 50m;

client_body_buffer_size 512k;

proxy_connect_timeout1024;

proxy_send_timeout960;

proxy_read_timeout900;

proxy_buffer_size 128k;

proxy_buffers32128k;

proxy_busy_buffers_size 512k;#stub_status off;#啟用nginx狀態頁

}#定義錯誤提示頁面

#error_page 500 502 503 504 /50.html;

#location = error/50.html {

#root /var/www/website;

#}

}

}

總結

以上是生活随笔為你收集整理的nginx mysql设置远程连接超时_nginx中的超时设置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。