博文精选 | nginx 性能优化 -- 配置解析
2022-07-21 10:35:06
F5小安
PHPWord
文章速览:
行业:互联网
关键字:nginx、负载均衡
摘要:nginx 在测试工作中经常会打交道,常用作于代理和负载均衡。尤其是在性能测试时,对他的调优不可小觑。
阅读时长:10分钟
以下文章来源于InfoQ!作者:箭上有毒

nginx 在测试工作中经常会打交道,常用作于代理和负载均衡。尤其是在性能测试时,对他的调优不可小觑。
分享一份工作中总结下来的 nginx 性能调优配置,已添加注释。有疑问或者不正确之处,欢迎指出!
worker_processes 4;
worker_cpu_affinity 00000001 00000010 00000100 00001000;
error_log /usr/local/nginx/logs/error.log error;
events {
worker_connections 65535;
use epoll;
multi_accept on;
}
worker_rlimit_nofile 65535;
http {
include 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 '
'"$upstream_addr" "$upstream_status" "$upstream_response_time" "$request_time"';
access_log /usr/local/nginx/logs/access.log main;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
keepalive_timeout 65;
vhost_traffic_status_zone;
vhost_traffic_status_filter_by_host on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
large_client_header_buffers 4 4k;
client_header_buffer_size 4k;
open_file_cache max=65535 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
upstream web_app {
least_conn;
server 192.168.226.130:8080 weight=2 max_fails=2 fail_timeout=30s;
server 192.168.226.128:8080 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
root html;
index index.html index.htm;
location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://web_app;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
include fastcgi_params;
}
vhost_traffic_status on;
location /nginx_status {
stub_status on;
access_log off;
vhost_traffic_status_display;
vhost_traffic_status_display_format html;
}
}
}
复制代码
以上是针对nginx 性能优化 -- 配置解析的分享,希望对大家有帮助!
阅读原文
声明:本文章版权归原作者及原出处所有 。凡本社区注明“来源:XXX或转自:XXX”的作品均转载自其它媒体,转载目的在于传递分享更多知识,内容为作者个人观点,仅供参考,并不代表本社区赞同其观点和对其真实性负责。本社区转载的文章,我们已经尽可能的对作者和来源进行了注明,若因故疏忽,造成漏注,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本社区拥有对此声明的最终解释权。
发布评论