nginx性能调优要点
- - 枯惠1、提高worker连接限制. 3、配置UpStream连接复用. 4、配置CPU亲和性与进程优化级. 缓存存放的目录
# keys_zone:. 缓存 zone名为 CACHE, 内存分配大小为 1024M,每M大约能存储8000个key
# loader_files:. 最大加载文件数量 (缺省: 100)
# loader_threshold:.
events {
worker_connections 100000;
}
提示:缺省为1024
worker_processes auto;
upstream demo1 {
server 1.1.1.1:80;
keepalive 128;
}
以双核为例
worker_processes 2;
worker_cpu_affinity 0101 1010;
worker_priority -20;
access_log /var/log/nginx/access.log main buffer=1m;
# filename: proxy_cache.conf
proxy_cache_path /data/nginx/proxy_cache levels=1:2 keys_zone=CACHE:1024m max_size=10g inactive=12h use_temp_path=off;
# cache_path: 缓存存放的目录
# keys_zone: 缓存 zone名为 CACHE, 内存分配大小为 1024M,每M大约能存储8000个key
# loader_files: 最大加载文件数量 (缺省: 100)
# loader_threshold: 迭代的持续时间,以毫秒为单位(缺省: 200)
# max_size: 缓存最大上限空间
# inactive: 清空 12h 没有访问过的文件,缺省10分钟
# use_temp_path: 为off时将在缓存直接写到proxy_cache_path目录下,on时先写入到proxy_temp_path然后重命名到 proxy_cache_path下[建议使用off]
proxy_cache_key $scheme$host$request_method$request_uri;
proxy_no_cache $cookie_nocache $arg_nocache $http_authorization;
# filename: gzip.conf
gzip on;
gzip_min_length 4k;
gzip_buffers 4 256k;
gzip_comp_level 6;
gzip_types application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
提示: 也可以使用Google的br压缩算法(需要手动编译)