nginx高性能配置的几个重要参数(java web应用)
Posted birduncle
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nginx高性能配置的几个重要参数(java web应用)相关的知识,希望对你有一定的参考价值。
互联网上讲述nginx高并发配置的比较多,主要是nginx+php。本博讲述nginx java web应用配置,实现高并发。
配置cpu核数
worker_processes 10;
worker_rlimit_nofile 102400;
配置epoll网络模型 worker_connections线程数,开到上万
events {
use epoll;
worker_connections 10240;
multi_accept on;
}
图片资源cache
http{
log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘
‘$status $body_bytes_sent "$http_referer" ‘
‘"$http_user_agent" "$http_x_forwarded_for"‘;
access_log logs/access.log main;
#控制缓冲区溢出攻击
client_body_buffer_size 1K;
client_header_buffer_size 1k;
client_max_body_size 1k;
large_client_header_buffers 2 1k;
##cache##
proxy_connect_timeout 5;
proxy_read_timeout 60;
proxy_send_timeout 5;
proxy_buffer_size 16k;
proxy_buffers 4 64k;
gzip_proxied any;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
proxy_temp_path /home/temp_dir;
proxy_cache_path /home/cache levels=1:2 keys_zone=<span style="color:#ff0000;"><strong>cache_one</strong></span>:200m inactive=1d max_size=1g;
#gzip#
gzip on;
gzip_vary on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 4;
gzip_http_version 1.0;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
gzip_disable "MSIE [1-6].";
}
#图片前端缓存
location ~ .*.(jsp|do|action)?$
{
# $server_port 可以不要,只有nginx的端口是非80情况下有效
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://tc;
}
location ~ .*.(gif|jpg|png|htm|html|css|flv|ico|swf) {
proxy_pass http://tc;
proxy_redirect off;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_cache <span style="color:#ff0000;"><strong>cache_one</strong></span>;
proxy_cache_valid 200 302 1h;
proxy_cache_valid 301 1d;
proxy_cache_valid any 1m;
expires 30d;
}
location ~ .*.(js)?$
{
expires 1h;
}
linux操作系统配置
vi /etc/sysctl.conf增加或者修改参数
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_tw_reuse = 1
net.nf_conntrack_max = 655360
net.netfilter.nf_conntrack_tcp_timeout_established = 1200
kernel.shmall = 4294967296
net.ipv4.tcp_max_tw_buckets =6000
vi /etc/security/limits.conf
* soft nofile 1024000
* soft nproc 1024000
* hard nofile 1024000
* hard nproc 1024000
以上是关于nginx高性能配置的几个重要参数(java web应用)的主要内容,如果未能解决你的问题,请参考以下文章