How to configure seven tiers of load in nginx
This article shows you how to configure the seven-tier load of nginx, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
Specific configuration:
Upstream service {
Server 10.3.1.1:8913 max_fails=5 fail_timeout=10s weight=10
Server 10.3.1.2:8913 max_fails=5 fail_timeout=10s weight=10
}
Server {
Listen 80
Server_name www.test.com
Location / {
Proxy_set_header Host $host
# Custom for debug field. If you don't add it, the backend cannot get this field.
Proxy_set_header unique_id $http_unique_id
Proxy_set_header trace_id $http_trace_id
Proxy_set_header X-Real-IP $remote_addr
Proxy_set_header X-Forwarded-Proto $scheme
Proxy_set_header X-Forwarded-For $remote_addr
Proxy_connect_timeout 30
Proxy_send_timeout 20
Proxy_read_timeout 20
Proxy_buffer_size 4k
Proxy_buffers 4 32k
Proxy_busy_buffers_size 64k
Proxy_pass http://service;
}
}
The following configurations have been modified in http:
Include mime.types
Default_type application/octet-stream
Server_names_hash_max_size 10240
Server_names_hash_bucket_size 2048
Client_max_body_size 3m
Client_body_buffer_size 256k
# enable the configuration with underscores in header
Underscores_in_headers on
# modify the log recording format. Json format is convenient for ELK to collect.
Log_format json escape=json'{remote_addr ":" $remote_addr ",'
'"@ timestamp": "$time_iso8601",'
'"request_uri": "$request_uri",'
'"verb": "$request_method",'
'"httpversion": "$server_protocol",'
'"response": "$status",'
'"body_bytes_sent": "$body_bytes_sent",'
'"referrer": "$http_referer",'
'"user_agent": "$http_user_agent",'
'"http_x_forwarded_for": "$http_x_forwarded_for",'
'"http_unique_id": "$http_unique_id",'
'"http_trace_id": "$http_trace_id",'
'"server_name": "$host",'
'"request_time": "$request_time",'
'"upstream_response_time": "$upstream_response_time",'
'"realpath_root": "$realpath_root",'
'"cookie": "$http_cookie",'
'"request_body": "$request_body",'
'"nginx_version": "$nginx_version",'
'"scheme": "$scheme"}'
Access_log / data/log/tmp.log json
The above is how to configure seven layers of load in nginx. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.