解決nginx 503 Service Temporarily Unavailable方法示例
最近網(wǎng)站刷新后經(jīng)常出現(xiàn)503 Service Temporarily Unavailable錯(cuò)誤,有時(shí)有可以,聯(lián)想到最近在nginx.conf里做了單ip訪(fǎng)問(wèn)次數(shù)限制,(limit_req_zone $binary_remote_addr zone=allips:20m rate=20r/s;) 把這個(gè)數(shù)量放大后在刷新發(fā)現(xiàn)問(wèn)題解決。(還順便把這個(gè)改大了 limit_req zone=allips burst=50 nodelay; )為了證實(shí)該問(wèn)題,反復(fù)改動(dòng)該數(shù)量測(cè)試發(fā)現(xiàn)問(wèn)題確實(shí)在這。這個(gè)數(shù)量設(shè)得太小有問(wèn)題,通過(guò)fiddler發(fā)現(xiàn)web頁(yè)面刷新一下,因?yàn)轫?yè)面上引用的js,css,圖片都算一個(gè)連接。所以單個(gè)頁(yè)面刷新下就有可能刷爆這個(gè)限制,超過(guò)這個(gè)限制就會(huì)提示503 Service Temporarily Unavailable。
附上nginx.conf
#user nobody; worker_processes 1; #worker_rlimit_nofile 100000; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; ##cache## proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/temp_dir; proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1d max_size=30g; ##end## #limit per ip per second access times 10 limit_req_zone $binary_remote_addr zone=allips:20m rate=20r/s; #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; upstream myweb80{ ip_hash; server 192.168.3.105:80; server 192.168.3.103:80; } upstream myweb8080{ ip_hash; server 192.168.3.222:10080; #server 192.168.3.103:8080; } upstream myweb10086{ ip_hash; server 192.168.3.102:10086; server 192.168.3.108:10086; } upstream myweb443{ ip_hash; server 192.168.3.105:443; server 192.168.3.103:443; } # another virtual host using mix of IP-, name-, and port-based configuration # server { listen 80; allow 218.17.158.2; allow 127.0.0.0/24; allow 192.168.0.0/16; allow 58.251.130.1; allow 183.239.167.3; allow 61.145.164.1; deny all; server_name myweb.com; location / { proxy_pass http://myweb80; proxy_set_header X-Real-IP $remote_addr; limit_req zone=allips burst=50 nodelay; } } server { listen 8080; allow 218.17.158.2; allow 127.0.0.0/24; allow 192.168.0.0/16; allow 58.251.130.1; allow 183.239.167.3; allow 61.145.164.1; deny all; location / { proxy_pass http://myweb8080; proxy_set_header X-Real-IP $remote_addr; limit_req zone=allips burst=50 nodelay; } } # HTTPS server # server { listen 10086 ssl; server_name localhost; allow 218.17.158.2; allow 127.0.0.0/24; allow 192.168.0.0/16; allow 58.251.130.1; allow 183.239.167.3; allow 61.145.164.1; #deny all; ssl_certificate ssl/1_www.myweb.com_bundle.crt; ssl_certificate_key ssl/2_www.myweb.com.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; location / { proxy_pass https:// myweb10086; #roft html; #index index.html index.htm; } } 服務(wù)器{ listen 443 ssl; server_name localhost; ssl_certificate ssl / 1_www.myweb.com_bundle.crt; ssl_certificate_key ssl / 2_www.myweb.com.key; #ssl_session_cache共享:SSL:1m; #ssl_session_timeout 5m; #ssl_ciphers HIGH:!aNULL:!MD5; #ssl_prefer_server_ciphers on; location / { proxy_pass https:// myweb443; #roft html; #roft html; #index index.html index.htm; } } }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Nginx緩存在服務(wù)端 代理和客戶(hù)端的區(qū)別深入探索
這篇文章主要介紹了Nginx緩存在服務(wù)端 代理和客戶(hù)端的區(qū)別深入探索,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-10-10nginx如何設(shè)置禁止訪(fǎng)問(wèn)PHP腳本
禁止訪(fǎng)問(wèn)?PHP?腳本可以通過(guò)?Nginx?服務(wù)器配置中的多種方式來(lái)實(shí)現(xiàn),這篇文章主要為大家整理了一些常見(jiàn)的方法,感興趣的小伙伴可以參考下2023-09-09Ubuntu?22.04.1?LTS?編譯安裝?nginx-1.22.1的配置過(guò)程
Ubuntu安裝Nginx有兩種方式,一種是通過(guò)命令的方式,這種方式安裝的Nginx版本低,之前漏掃掃出來(lái)Nginx版本低,需要升級(jí)所以現(xiàn)在用編譯的方式安裝版本高點(diǎn)的,本文介紹Ubuntu22.04.1?LTS編譯安裝nginx1.22.1的配置過(guò)程,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧2024-01-01在Nginx服務(wù)器上配置Google反向代理的基本方法
這篇文章主要介紹了在Nginx服務(wù)器上配置Google反向代理的基本方法,文中使用到了SSL來(lái)加密反向代理,需要的朋友可以參考下2015-12-12Nginx開(kāi)啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法
這篇文章主要介紹了Nginx開(kāi)啟一個(gè)參數(shù)就能讓你的WEB性能提升3倍的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2019-03-03詳解nginx高并發(fā)場(chǎng)景下的優(yōu)化
這篇文章主要介紹了詳解nginx高并發(fā)場(chǎng)景下的優(yōu)化,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-09-09解決Nginx 配置 proxy_pass 后 返回404問(wèn)題
這篇文章主要介紹了Nginx 配置 proxy_pass 后 返回404問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01nginx使用IPV6的相關(guān)配置項(xiàng)介紹
這篇文章主要介紹了nginx使用IPV6的相關(guān)配置項(xiàng)介紹,首先查看編譯參數(shù)是否編譯了IPV6模塊,然后介紹了監(jiān)聽(tīng)I(yíng)PV6的配置語(yǔ)法,需要的朋友可以參考下2014-07-07Nginx+Keepalived實(shí)現(xiàn)雙機(jī)主備的方法
這篇文章主要介紹了Nginx+Keepalived實(shí)現(xiàn)雙機(jī)主備的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03