최고의 성능 을 위 한 Nginx - 블 로그 - 버 러 온라인
1
2
cp
/etc/nginx/nginx
.conf
/etc/nginx/nginx
.conf.orig
vim
/etc/nginx/nginx
.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# This number should be, at maximum, the number of CPU cores on your system.
# (since nginx doesn't benefit from more than one worker per CPU.)
# CPU , 1 Nginx 。
worker_processes 24;
# Number of file descriptors used for Nginx. This is set in the OS with 'ulimit -n 200000'
# or using /etc/security/limits.conf
# Nginx , "ulimit -n 200000", /etc/security/limits.conf 。
worker_rlimit_nofile 200000;
# only log critical errors
# critical
error_log
/var/log/nginx/error
.log crit
# Determines how many clients will be served by each worker process.
# (Max clients = worker_connections * worker_processes)
# "Max clients" is also limited by the number of socket connections available on the system (~64k)
# Nginx ,( = * )
# socket ( 64K )
worker_connections 4000;
# essential for linux, optmized to serve many clients with each thread
# Linux , 。
use epoll;
# Accept as many connections as possible, after nginx gets notification about a new connection.
# May flood worker_connections, if that option is set too low.
# , worker_connections , 。
multi_accept on;
# Caches information about open FDs, freqently accessed files.
# Changing this setting, in my environment, brought performance up from 560k req/sec, to 904k req/sec.
# I recommend using some varient of these options, though not the specific values listed below.
# FDs( / )
# , , 560k / 904k / 。
# , 。
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
# Buffer log writes to speed up IO, or disable them altogether
# IO , 。
# access_log /var/log/nginx/access.log main buffer=16k;
access_log off;
# Sendfile copies data between one FD and other from within the kernel.
# More efficient than read() + write(), since the requires transferring data to and from the user space.
# sendfile , FD , read() + write() 。
sendfile on;
# Tcp_nopush causes nginx to attempt to send its HTTP response head in one packet,
# instead of using partial frames. This is useful for prepending headers before calling sendfile,
# or for throughput optimization.
# tcp_nopush ,Nginux HTTP 。
# sendfile HTTP , 。
tcp_nopush on;
# don't buffer data-sends (disable Nagle algorithm). Good for sending frequent small bursts of data in real time.
# data-sends ( Nagle ), 。
tcp_nodelay on;
# Timeout for keep-alive connections. Server will close connections after this time.
# keep-alive , 。
keepalive_timeout 30;
# Number of requests a client can make over the keep-alive connection. This is set high for testing.
# keep-alive , , 。
keepalive_requests 100000;
# allow the server to close the connection after a client stops responding. Frees up socket-associated memory.
# , socket 。
reset_timedout_connection on;
# send the client a "request timed out" if the body is not loaded by this time. Default 60.
# , 60 。
client_body_timeout 10;
# If the client stops reading data, free up the stale client connection after this much time. Default 60.
# , , , 60 。
send_timeout 2;
# Compression. Reduces the amount of data that needs to be transferred over the network
# , 。
gzip
on;
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text
/plain
text
/css
text
/xml
text
/javascript
application
/x-javascript
application
/xml
;
gzip_disable
"MSIE [1-6]."
;
1
vim
/etc/sysctl
.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Increase system IP port limits to allow for more connections
# IP ,
net.ipv4.ip_local_port_range = 2000 65000
net.ipv4.tcp_window_scaling = 1
# number of packets to keep in backlog before the kernel starts dropping them
# ,
net.ipv4.tcp_max_syn_backlog = 3240000
# increase socket listen backlog
# socket
net.core.somaxconn = 3240000
net.ipv4.tcp_max_tw_buckets = 1440000
# Increase TCP buffer sizes
# TCP
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
net.ipv4.tcp_congestion_control = cubic
설정 을 수정 할 때마다 다음 명령 을 실행 해 야 합 니 다.
1
sysctl -p
/etc/sysctl
.conf
전문 을 읽다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.