How to solve nginx 503 Service Temporarily Unavailable

How to solve nginx 503 Service Temporarily Unavailable

Recently, after refreshing the website, 503 Service Temporarily Unavailable error often occurs. Sometimes it works. I thought about the recent limit on the number of visits to a single IP address in nginx.conf (limit_req_zone $binary_remote_addr zone=allips:20m rate=20r/s;). After increasing this number and refreshing the website, I found that the problem was solved. (I also increased this limit_req zone=allips burst=50 nodelay; ) To confirm the problem, I repeatedly changed the number and found that the problem was indeed here. There is a problem if this number is set too small. Through fiddler, it is found that the web page needs to be refreshed because the js, css, and pictures referenced on the page are all counted as one connection. Therefore, a single page refresh may exceed this limit, and if this limit is exceeded, a 503 Service Temporarily Unavailable message will be displayed.

Attach 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; 
    } 
  }
 
  server{ 
    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 shared: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; 
    } 
  } 
}

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Solution to the 404/503 problem when logging in to TeamCenter12
  • SVN error: Error Updating changes: svn: E155037 solution
  • How to solve the error 2503 and 2502 when installing Node.js on Windows
  • Solution to 503 error when deploying Python program in Apache
  • Parsing server common error codes 500, 501, 502, 503, 504, 505
  • Server error code 500 501 502 503 504 505 Detailed explanation
  • What is the 503 Service Temporarily Unavailable error?
  • 503 service unavailable error solution explanation

<<:  mysql 8.0.16 winx64.zip installation and configuration method graphic tutorial

>>:  Graphical analysis of MYSQL5.7 configuration file location in Windows environment

Recommend

Delegating Privileges in Linux Using Sudo

Introduction to sudo authority delegation su swit...

jQuery achieves the effect of advertisement scrolling up and down

This article shares the specific code of jQuery t...

Solution to 2059 error when connecting Navicat to MySQL

Recently, when I was learning Django, I needed to...

A brief discussion on whether CSS animation will be blocked by JS

The animation part of CSS will be blocked by JS, ...

Solution to the problem of saving format in HTML TextArea

The format of textarea can be saved to the databas...

Detailed tutorial on Tomcat installation and deployment in Windows 10

Table of contents 1 Java environment configuratio...

Detailed explanation of CSS margin overlap and solution exploration

I recently reviewed some CSS-related knowledge po...

ElementUI implements cascading selector

This article example shares the specific code of ...

MySQL query optimization using custom variables

Table of contents Optimizing sorting queries Avoi...

Jenkins Docker static agent node build process

A static node is fixed on a machine and is starte...

61 Things Every Web Developer Should Know

Normally, you'll need to read everyone's s...