解决nginx 503 Service Temporarily Unavailable方法示例
最近网站刷新后经常出现503ServiceTemporarilyUnavailable错误,有时有可以,联想到最近在nginx.conf里做了单ip访问次数限制,(limit_req_zone$binary_remote_addrzone=allips:20mrate=20r/s;)把这个数量放大后在刷新发现问题解决。(还顺便把这个改大了limit_reqzone=allipsburst=50nodelay; )为了证实该问题,反复改动该数量测试发现问题确实在这。这个数量设得太小有问题,通过fiddler发现web页面刷新一下,因为页面上引用的js,css,图片都算一个连接。所以单个页面刷新下就有可能刷爆这个限制,超过这个限制就会提示503ServiceTemporarilyUnavailable。
附上nginx.conf
#usernobody; worker_processes1; #worker_rlimit_nofile100000; #error_loglogs/error.log; #error_loglogs/error.lognotice; #error_loglogs/error.loginfo; #pidlogs/nginx.pid; events{ worker_connections1024; } http{ includemime.types; default_typeapplication/octet-stream; ##cache## proxy_connect_timeout5; proxy_read_timeout60; proxy_send_timeout5; proxy_buffer_size16k; proxy_buffers464k; proxy_busy_buffers_size128k; proxy_temp_file_write_size128k; proxy_temp_path/home/temp_dir; proxy_cache_path/usr/local/nginx/cachelevels=1:2keys_zone=cache_one:200minactive=1dmax_size=30g; ##end## #limitperippersecondaccesstimes10 limit_req_zone$binary_remote_addrzone=allips:20mrate=20r/s; #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"' #'$status$body_bytes_sent"$http_referer"' #'"$http_user_agent""$http_x_forwarded_for"'; #access_loglogs/access.logmain; sendfileon; #tcp_nopushon; #keepalive_timeout0; keepalive_timeout65; #gzipon; upstreammyweb80{ ip_hash; server192.168.3.105:80; server192.168.3.103:80; } upstreammyweb8080{ ip_hash; server192.168.3.222:10080; #server192.168.3.103:8080; } upstreammyweb10086{ ip_hash; server192.168.3.102:10086; server192.168.3.108:10086; } upstreammyweb443{ ip_hash; server192.168.3.105:443; server192.168.3.103:443; } #anothervirtualhostusingmixofIP-,name-,andport-basedconfiguration # server{ listen80; allow218.17.158.2; allow127.0.0.0/24; allow192.168.0.0/16; allow58.251.130.1; allow183.239.167.3; allow61.145.164.1; denyall; server_namemyweb.com; location/{ proxy_passhttp://myweb80; proxy_set_headerX-Real-IP$remote_addr; limit_reqzone=allipsburst=50nodelay; } } server{ listen8080; allow218.17.158.2; allow127.0.0.0/24; allow192.168.0.0/16; allow58.251.130.1; allow183.239.167.3; allow61.145.164.1; denyall; location/{ proxy_passhttp://myweb8080; proxy_set_headerX-Real-IP$remote_addr; limit_reqzone=allipsburst=50nodelay; } } #HTTPSserver # server{ listen10086ssl; server_namelocalhost; allow218.17.158.2; allow127.0.0.0/24; allow192.168.0.0/16; allow58.251.130.1; allow183.239.167.3; allow61.145.164.1; #denyall; ssl_certificatessl/1_www.myweb.com_bundle.crt; ssl_certificate_keyssl/2_www.myweb.com.key; #ssl_session_cacheshared:SSL:1m; #ssl_session_timeout5m; #ssl_ciphersHIGH:!aNULL:!MD5; #ssl_prefer_server_cipherson; location/{ proxy_passhttps://myweb10086; #rofthtml; #indexindex.htmlindex.htm; } } 服务器{ listen443ssl; server_namelocalhost; ssl_certificatessl/1_www.myweb.com_bundle.crt; ssl_certificate_keyssl/2_www.myweb.com.key; #ssl_session_cache共享:SSL:1m; #ssl_session_timeout5m; #ssl_ciphersHIGH:!aNULL:!MD5; #ssl_prefer_server_cipherson; location/{ proxy_passhttps://myweb443; #rofthtml; #rofthtml; #indexindex.htmlindex.htm; } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。