Several important parameters for nginx high-performance java web Applications
On the Internet, nginx has many high-concurrency configurations, mainly nginx + php. This article describes how to configure nginx java web applications to achieve high concurrency. Configure the key points. See the following section.
Configure the number of cpu Cores
worker_processes 10;
worker_rlimit_nofile 102400;
Configure the epoll network model worker_connections thread count to tens of thousands
events { use epoll; worker_connections 10240;}
Image resource cache
Http {log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request" ''$ status $ response" $ http_referer "'' "$ http_user_agent" "$ http_x_forwarded_for "'; access_log logs/access. log main; # control the buffer overflow attack limit 1 K; Limit 1 k; client_max_body_size 1 k; Limit 2 1 k; ## cache ## proxy_connect_timeout 5; proxy_read_timeout 60; proxy_send_timeout 5; proxy_buffer_size 16 k; proxy_buffers 4 64 k; gzip_proxied any; Limit 128 k; Limit 128 k; proxy_temp_path/home/temp_dir; proxy_cache_path/home/cache levels = keys_zone =Cache_one: 200 m inactive = 1d max_size = 1g; # gzip on; gzip_vary on; gzip_min_length 1 k; gzip_buffers 4 8 k; gzip_comp_level 4; gzip_http_version 1.0; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml + rss text/javascript; gzip_disable "MSIE [1-6] \. ";}
# Image front-end cache
Location ~ . * \. (Jsp | do | action )? $ {# $ Server_port is optional. Only the nginx port is valid when it is not 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_cacheCache_one; Proxy_cache_valid 200 302 1 h; proxy_cache_valid 301 1d; proxy_cache_valid any 1 m; expires 30d;} location ~ . * \. (Js )? $ {Expires 1 h ;}
There are many Load Balancing policies for nginx Server Load balancer. Here we mainly use three types: ip_hash: Ip viscosity. For web clients, there is no mature session replication solution, and Ip viscosity is used. After a user logs on, the session is kept on a PC. Least_conn: Least connections round-robin: default. Distribute requests to backend servers in the order of request time
Other policiesFair: a third party, not studied. Requests are allocated based on the response time of the backend server. url_hash is preferentially allocated for short response time: third-party, not studied. Linux operating system
Vi/etc/sysctl. conf add or modify parameters
net.ipv4.tcp_timestamps = 0net.ipv4.tcp_synack_retries = 1net.ipv4.tcp_syn_retries = 1net.ipv4.tcp_tw_recycle = 1net.ipv4.tcp_tw_reuse = 1net.nf_conntrack_max = 655360net.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