Nginx动静分离及性能调优实践

直接看配置文件!直接看配置文件!直接看配置文件!

#user  nobody;
worker_processes  8;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#----------------Nginx优化参数---------------Start-----------------###
worker_rlimit_nofile 65535;
#----------------Nginx优化参数---------------End-------------------###
events {
    worker_connections  1024;
	use epoll;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #----------------Nginx优化参数--------------Start------------------###
	open_file_cache          max=2048 inactive=20s;	#最多缓存n个文件,缓存多少时间
    open_file_cache_valid    30s;	#多少时间检查一次,如果发现30s内没有用过2次的删除
    open_file_cache_min_uses 2;	#在30S中没有使用到这个配置的次数的话就删除
    open_file_cache_errors   on;
	
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 15;
    
	fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

	#开启GZIP
	gzip  on;
    gzip_disable     "MSIE [1-6]\.";
    gzip_proxied any;
	gzip_http_version 1.1;
    gzip_comp_level 4;
    gzip_buffers 16 8k;
    gzip_min_length    1k;
    gzip_vary on;
    gzip_types text/plain text/css image/gif image/jpeg image/png application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
   
	#----------------Nginx优化参数---------------End-------------------###
    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_response_time $request_time '
		      '$http_true_client_ip ';
    #---优化项目----------------关闭Nginx访问日志
    # access_log  logs/access.log  main;
    server_tokens off;  #关闭版本显示 
	
    sendfile        on;
 
	#防止ddos攻击
    client_header_timeout 10;
    client_body_timeout 10;
	
    #h5-no session
	upstream balanceNoSessionServer{
	     #---优化项目----------------转换为本机物理IP
		 server 10.3.1.18:8003 ;
		 server 10.3.1.18:8004 ;
		 server 10.3.1.18:8005 ;
		 server 10.3.1.18:8006 ;
	}
	#h5-star service 
	upstream balanceSessionServer{
	     sticky httponly;
		 #---优化项目----------------转换为本机物理IP
		 server 10.3.1.18:8003 ;
		 server 10.3.1.18:8004 ;
		 server 10.3.1.18:8005 ;
		 server 10.3.1.18:8006 ;
	}
    server {
        listen       8088;
        server_name  localhost;

        #charset koi8-r;
		
		#--------------------------动静分离-----------------静态资源映射-------------------#
        location ~ /(proh5|proh5-itr-services)/.*\.(gif|jpg|jpeg|png|bmp|ico|css|js|html)$ {
		   #指定静态资源根目录
		   #静态资源查找逻辑为:/app/nginx/static/proh5/index.html
		   #                    /app/nginx/static/proh5-itr-services/index.html
		   root /app/nginx/static;
		}
		
		#--------------------------动静分离-----------------动态资源映射-------------------#
        location ~ /proh5/.*\.(jsp|do|action|jspx)$ {
            proxy_pass  http://balanceNoSessionServer$request_uri; 
			proxy_set_header X-Forwarded-Host $host;
			proxy_set_header X-Forwarded-Server $host;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Real-IP  $remote_addr;  #支撑后端获取源IP
			proxy_redirect off;
			proxy_set_header Host $http_host;
			proxy_set_header Connection Close;
			port_in_redirect off;
			proxy_connect_timeout 60s;
			proxy_read_timeout 60s;
			proxy_send_timeout 60s;
			proxy_buffer_size 4k;
			proxy_buffers 6 32k;
			proxy_busy_buffers_size 64k;
			proxy_temp_file_write_size 64k;
			proxy_intercept_errors off;
			#---------------------------------Nginx优化参数--------------Start------------------###
            client_body_buffer_size 128k;
        }
		location ~ /proh5-itr-services/.*\.(jsp|do|action|jspx)$ {
            proxy_pass  http://balanceSessionServer$request_uri; 
			proxy_set_header X-Forwarded-Host $host;
			proxy_set_header X-Forwarded-Server $host;
			proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
			proxy_set_header X-Real-IP  $remote_addr;   #支撑后端获取源IP
			proxy_redirect off;
			proxy_set_header Host $http_host;
			proxy_set_header Connection Close;
			port_in_redirect off;
			proxy_connect_timeout 60s;
			proxy_read_timeout 60s;
			proxy_send_timeout 60s;
			proxy_buffer_size 4k;
			proxy_buffers 6 32k;
			proxy_busy_buffers_size 64k;
			proxy_temp_file_write_size 64k;
			proxy_intercept_errors off;
			#---------------------------------Nginx优化参数--------------Start------------------###
            client_body_buffer_size 128k;
        }
		
    	location ~ ^/WEB-INF/ {
        	deny  all;
    	}

        location /res {
            alias   /app2/resource/images;
            index  index.html index.htm;
			expires 1d;
        }

        #设置健康检查页面
		location = /healthcheck.html {
            root   /app/nginx/html;
			access_log off; #关闭健康检查访问日志
        }
		#设置404页面[/app/nginx/html目录下的文件]
		error_page  404 403             /404.html;
		location = /404.html {
            root   /app/nginx/html;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /app/nginx/html;
        }
        
    }
}


你可能感兴趣的:(性能调优,Linux)