系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > server > anz > 详细页面

解决nginx 503 Service Temporarily Unavailable方法示例

时间:2019-12-10来源:系统城作者:电脑系统城

最近网站刷新后经常出现503 Service Temporarily Unavailable错误,有时有可以,联想到最近在nginx.conf里做了单ip访问次数限制,(limit_req_zone $binary_remote_addr zone=allips:20m rate=20r/s;) 把这个数量放大后在刷新发现问题解决。(还顺便把这个改大了 limit_req zone=allips burst=50 nodelay;   )为了证实该问题,反复改动该数量测试发现问题确实在这。这个数量设得太小有问题,通过fiddler发现web页面刷新一下,因为页面上引用的js,css,图片都算一个连接。所以单个页面刷新下就有可能刷爆这个限制,超过这个限制就会提示503 Service Temporarily Unavailable。

附上nginx.conf


 
  1. #user nobody;
  2. worker_processes 1;
  3. #worker_rlimit_nofile 100000;
  4. #error_log logs/error.log;
  5. #error_log logs/error.log notice;
  6. #error_log logs/error.log info;
  7.  
  8. #pid logs/nginx.pid;
  9.  
  10. events {
  11. worker_connections 1024;
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17.  
  18. ##cache##
  19. proxy_connect_timeout 5;
  20. proxy_read_timeout 60;
  21. proxy_send_timeout 5;
  22. proxy_buffer_size 16k;
  23. proxy_buffers 4 64k;
  24. proxy_busy_buffers_size 128k;
  25. proxy_temp_file_write_size 128k;
  26. proxy_temp_path /home/temp_dir;
  27. proxy_cache_path /usr/local/nginx/cache levels=1:2 keys_zone=cache_one:200m inactive=1dmax_size=30g;
  28. ##end##
  29. #limit per ip per second access times 10
  30. limit_req_zone $binary_remote_addr zone=allips:20m rate=20r/s;
  31.  
  32. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  33. # '$status $body_bytes_sent "$http_referer" '
  34. # '"$http_user_agent" "$http_x_forwarded_for"';
  35.  
  36. #access_log logs/access.log main;
  37.  
  38. sendfile on;
  39. #tcp_nopush on;
  40.  
  41. #keepalive_timeout 0;
  42. keepalive_timeout 65;
  43.  
  44. #gzip on;
  45. upstream myweb80{
  46. ip_hash;
  47. server 192.168.3.105:80;
  48. server 192.168.3.103:80;
  49. }
  50.  
  51. upstream myweb8080{
  52. ip_hash;
  53. server 192.168.3.222:10080;
  54. #server 192.168.3.103:8080;
  55. }
  56. upstream myweb10086{
  57. ip_hash;
  58. server 192.168.3.102:10086;
  59. server 192.168.3.108:10086;
  60. }
  61. upstream myweb443{
  62. ip_hash;
  63. server 192.168.3.105:443;
  64. server 192.168.3.103:443;
  65. }
  66.  
  67. # another virtual host using mix of IP-, name-, and port-based configuration
  68. #
  69. server {
  70. listen 80;
  71. allow 218.17.158.2;
  72. allow 127.0.0.0/24;
  73. allow 192.168.0.0/16;
  74. allow 58.251.130.1;
  75. allow 183.239.167.3;
  76. allow 61.145.164.1;
  77. deny all;
  78. server_name myweb.com;
  79. location / {
  80. proxy_pass http://myweb80;
  81. proxy_set_header X-Real-IP $remote_addr;
  82. limit_req zone=allips burst=50 nodelay;
  83. }
  84. }
  85.  
  86. server {
  87. listen 8080;
  88. allow 218.17.158.2;
  89. allow 127.0.0.0/24;
  90. allow 192.168.0.0/16;
  91. allow 58.251.130.1;
  92. allow 183.239.167.3;
  93. allow 61.145.164.1;
  94. deny all;
  95. location / {
  96. proxy_pass http://myweb8080;
  97. proxy_set_header X-Real-IP $remote_addr;
  98. limit_req zone=allips burst=50 nodelay;
  99. }
  100. }
  101.  
  102. # HTTPS server
  103. #
  104. server {
  105. listen 10086 ssl;
  106. server_name localhost;
  107. allow 218.17.158.2;
  108. allow 127.0.0.0/24;
  109. allow 192.168.0.0/16;
  110. allow 58.251.130.1;
  111. allow 183.239.167.3;
  112. allow 61.145.164.1;
  113. #deny all;
  114. ssl_certificate ssl/1_www.myweb.com_bundle.crt;
  115. ssl_certificate_key ssl/2_www.myweb.com.key;
  116.  
  117. # ssl_session_cache shared:SSL:1m;
  118. # ssl_session_timeout 5m;
  119.  
  120. # ssl_ciphers HIGH:!aNULL:!MD5;
  121. # ssl_prefer_server_ciphers on;
  122.  
  123. location / {
  124. proxy_pass https:// myweb10086;
  125. #roft html;
  126. #index index.html index.htm;
  127. }
  128. }
  129.  
  130. 服务器{
  131. listen 443 ssl;
  132. server_name localhost;
  133.  
  134. ssl_certificate ssl / 1_www.myweb.com_bundle.crt;
  135. ssl_certificate_key ssl / 2_www.myweb.com.key;
  136.  
  137. #ssl_session_cache共享:SSL:1m;
  138. #ssl_session_timeout 5m;
  139.  
  140. #ssl_ciphers HIGH:!aNULL:!MD5;
  141. #ssl_prefer_server_ciphers on;
  142.  
  143. location / {
  144. proxy_pass https:// myweb443;
  145. #roft html;
  146. #roft html;
  147. #index index.html index.htm;
  148. }
  149. }
  150. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

分享到:

相关信息

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载