Detailed explanation of Nginx timeout configuration

Detailed explanation of Nginx timeout configuration

I recently used nginx in a project, and used Java in the backend. I found that one request took more than 1 minute to process in the backend, and the request Status Code was 504 Gateway Time-out.

Understand all the timeout-related configurations of nginx, as follows:

keepalive_timeout

HTTP has a KeepAlive mode, which tells the webserver to keep the TCP connection open after processing a request. If other requests are received from the client, the server will use this unclosed connection without establishing another connection.

http keep-alive, every request of a web page is HTTP (images, CSS, etc.), and opening an HTTP request requires establishing a TCP connection first. If a page has to open and close a TCP connection for each request, it will be a waste of resources. keepalive_timeout is the time that the TCP connection will remain when an HTTP request is completed. If another HTTP request comes at this time, the TCP connection will be reused. If there is no new request, the TCP connection will be closed.

user nginx;
worker_processes 1;
 
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
 
 
events {
  worker_connections 1024;
}
 
 
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;
  tcp_nodelay on;
 
 
  keepalive_timeout 65;
  client_max_body_size 8192m;
 
  #gzip on;
 
  #include /etc/nginx/conf.d/*.conf;
 
 
 
  server {
 listen 80 so_keepalive=30m::;
 listen 443 default ssl;
 
 ssl_certificate /etc/nginx/ssl/server.crt;
 ssl_certificate_key /etc/nginx/ssl/portalkey.key;
 #ssl_password_file /etc/nginx/ssl/ssl.pass;
 
 
    ssl_session_timeout 5m;
    ssl_protocols SSLv2 SSLv3 TLSv1;
    ssl_ciphers HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers on;
 
 location / {
 proxy_request_buffering off;
 proxy_pass http://127.0.0.1:8011/;
 proxy_connect_timeout 180;
    proxy_send_timeout 180;
    proxy_read_timeout 180;
    send_timeout 180;
 }
 location /test1_url/ {
 proxy_pass http://127.0.0.1:8008/;
 proxy_connect_timeout 180;
    proxy_send_timeout 180;
    proxy_read_timeout 180;
    send_timeout 180;
 }
 location /test2_url/ {
 proxy_pass http://127.0.0.1:3000/;
 proxy_connect_timeout 180;
    proxy_send_timeout 180;
    proxy_read_timeout 180;
    send_timeout 180;
 }
  }
}

# Configuration section: http, default 75s

keepalive_timeout 60;

  • send_timeout: Timeout for sending data to the client, 60s by default. If the client does not receive a byte within 60 consecutive seconds, the connection is closed.
  • proxy_connect_timeout: The connection timeout between nginx and the upstream server
  • proxy_read_timeout: nginx times out when receiving data from the upstream server, 60s by default. If no byte is received within 60 consecutive seconds, the connection is closed.
  • proxy_send_timeout: nginx sends data to the upstream server timeout, 60s by default. If no byte is sent within 60 consecutive seconds, the connection is closed.

so_timeout:

When a user opens a TCP connection with a server --> there is no traffic on this connection for a long time (so_keepalive timeout) --> the server sends a probe packet to see if the user is still alive --> if there is no response to the probe packet, the TCP connection is closed

so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]
so_keepalive=30m::10
  will set the idle timeout (TCP_KEEPIDLE) to 30 minutes, leave the probe interval (TCP_KEEPINTVL) at its system default, and set the probes count (TCP_KEEPCNT) to 10 probes.

Only one of the above three parameters can be used, and they cannot be used at the same time, such as so_keepalive=on, so_keepalive=off or so_keepalive=30s:: (which means waiting for 30 seconds without data packets to send a detection packet)

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:
  • Detailed explanation of Nginx timeout configuration
  • Solution to Nginx timeout when uploading large files
  • Detailed introduction to nginx timeout settings
  • Detailed explanation of how to configure timeout in Nginx server
  • Detailed explanation of Nginx timeout keeplive_timeout configuration steps

<<:  13 Most Frequently Asked Vue Modifiers in Interviews

>>:  How to correctly modify the ROOT password in MySql8.0 and above versions

Recommend

Small paging design

Let our users choose whether to move forward or ba...

Brief analysis of mysql scheduled backup tasks

Introduction In a production environment, in orde...

CSS to achieve floating customer service effect

<div class="sideBar"> <div>...

Linux disk management LVM usage

1. Introduction to LVM When we manage Linux disks...

Mobile web screen adaptation (rem)

Preface I recently sorted out my previous notes o...

Linux kernel device driver kernel debugging technical notes collation

/****************** * Kernel debugging technology...

How to use lodop print control in Vue to achieve browser compatible printing

Preface This control will have a watermark at the...

Whitespace processing in HTML/CSS and how to preserve whitespace in the page

Whitespace rules in HTML In HTML, multiple spaces...

Detailed explanation of JS ES6 variable destructuring assignment

Table of contents 1. What is deconstruction? 2. A...

Let's talk about MySQL joint query in detail

Table of contents Union query 1. Query the ID and...

About Zabbix custom monitoring items and triggers

Table of contents 1. Monitoring port Relationship...

How to implement gzip compression in nginx to improve website speed

Table of contents Why use gzip compression? nginx...

Detailed steps to deploy SpringBoot projects using Docker in Idea

Preface Project requirements: Install the Docker ...

Detailed explanation of how to use awk in Linux

Before learning awk, we should have learned sed, ...

Explanation of the working principle and usage of redux

Table of contents 1. What is redux? 2. The princi...