码迷,mamicode.com
首页 > 编程语言 > 详细

nginx高性能配置的几个重要参数(java web应用)

时间:2020-07-13 13:15:04      阅读:71      评论:0      收藏:0      [点我收藏+]

标签:event   溢出   操作   XML   val   缓冲区溢出   set   referer   access   

互联网上讲述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应用)

标签:event   溢出   操作   XML   val   缓冲区溢出   set   referer   access   

原文地址:https://www.cnblogs.com/birdUncle/p/13292688.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!