标签:nec inux 使用 key ext var ash test fast
nginx性能优化
1.worker_processes n;
nginx 进程数,一般为cpu的倍数
2.worker_cpu_affinity 00000001 00000010 ..
为每个进程分配cpu,可多写几个,也可将一个进程分配到多个cpu
3. worker_rlimit_nofile 65535;
nginx进程打开的最多文件描述符数目,查看linux系统文件描述符的方法
[root@ray ~]# sysctl -a | grep fs.file fs.file-max = 1599020 fs.file-nr = 10240 0 1599020
4.use epoll
使用epoll的I/O模型
5.worker_connections 65535;
每个进程序允许的最多连接数,理论上每台服务器的最大连接数为 worker_processes * worker_connections
6.keepalive_timeout 60;
keepalive超时时间
7.client_header_buffer_size 4k;
客户端请求头部的缓冲区大小,一般设置为系统分页大小的倍数。
[root@ray ~]# getconf PAGESIZE 4096
8.oepn_file_cache max=65535 inactive=60s;
为打开文件指定缓存,max值一般和打开文件数以值,inactive 指经过多长时间文件没被请求后删除缓存
9.open_file_cache_valid 80s;
多长时间检查一次缓存的有效信息
10.open_file_cache_min_uses 1;
user nginx; worker_processes 8; worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000; error_log /www/log/nginx_error.log crit; pid /usr/local/nginx/nginx.pid; worker_rlimit_nofile 204800; events { use epoll; worker_connections 204800; } http { include mime.types; default_type application/octet-stream; charset utf-8; server_names_hash_bucket_size 128; client_header_buffer_size 2k; large_client_header_buffers 4 4k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 60; fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 4k; fastcgi_buffers 8 4k; fastcgi_busy_buffers_size 8k; fastcgi_temp_file_write_size 8k; fastcgi_cache TEST; fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d; fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1; fastcgi_cache_use_stale error timeout invalid_header http_500; open_file_cache max=204800 inactive=20s; open_file_cache_min_uses 1; open_file_cache_valid 30s; tcp_nodelay on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.0; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; server { listen 8080; server_name xxx.com; index index.php index.htm; root /www/html/; location /status { stub_status on; } location ~ .*/.(php|php5)?$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } location ~ .*/.(gif|jpg|jpeg|png|bmp|swf|js|css)$ { expires 30d; } log_format access ‘$remote_addr — $remote_user [$time_local] “$request” ‘ ‘$status $body_bytes_sent “$http_referer” ‘ ‘”$http_user_agent” $http_x_forwarded_for’; access_log /www/log/access.log access; } }
标签:nec inux 使用 key ext var ash test fast
原文地址:https://www.cnblogs.com/ray-mmss/p/10388617.html