Nginx High-Performance Java Web application several important parameters

Source: Internet
Author: User
Tags epoll nginx load balancing

The internet on the high concurrency of nginx configuration is more, mainly nginx+php. Benbow describes the Nginx Java Web application configuration for high concurrency. Configure key points, see below


To configure the number of CPU cores

Worker_processes  10;
Worker_rlimit_nofile 102400;



Configure the Epoll network model Worker_connections threads to tens of thousands

Events {use    epoll;    Worker_connections  10240;}



Picture Resource Cache
Http{log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' $status $body _bytes_s              Ent "$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  ;p roxy_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 can not, only Nginx port is valid 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;p Roxy_ Cache <span style= "color: #ff0000;" ><strong>cache_one</strong></span>;p roxy_cache_valid 302 1h;proxy_cache_valid 301 1d;proxy _cache_valid any 1m;expires 30d;} Location ~. *\. (JS)? ${expires   


Nginx load Balancing Load balancing strategy is more, here are mainly used three kinds: ip_hash:ip sticky, for the web side there is no very mature session replication scheme, using IP sticky. After the user logs on, the session remains on a single PC. Least_conn: Minimum number of connections polling: Default. Assign to back-end servers in order of request time
Other StrategiesFairthird party, not studied. allocation of requests by the response time of the back-end server, with short response times for priority allocationUrl_hash: Third party , not studied. Linux operating system

vi/etc/sysctl.conf adding or modifying 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 = 
<p><span style= "background-image:initial; background-attachment:initial; background-size:initial; background-origin:initial; background-clip:initial; background-position:initial; background-repeat:initial; " >kernel.shmall = 4294967296</span></p><p><span style= "Font-family:arial, Helvetica, Sans-serif; background-image:initial; background-attachment:initial; background-size:initial; background-origin:initial; background-clip:initial; background-position:initial; background-repeat:initial; " >net.ipv4.tcp_max_tw_buckets =</span><span style= "font-family:arial, Helvetica, Sans-serif; background-image:initial; background-attachment:initial; background-size:initial; background-origin:initial; background-clip:initial; background-position:initial; background-repeat:initial; " >6</span><span style= "font-family:arial, Helvetica, Sans-serif; background-image:initial; background-attachment:initial; Background-size:initial; background-origin:initial; background-clip:initial; background-position:initial; background-repeat:initial; " >000</span></p>

Vi/etc/security/limits.conf

* Soft nofile 1024000   * Soft Nproc 1024000    * Hard nofile 1024000* hard Nproc 1024000




Nginx High-Performance Java Web application several important parameters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.