nginx+tomcat单站点本地代理优化笔录(1)

 

单台tomcat,使用nginx合理搭配,无论从安全、效率方面都会有一定的提升。

从nginx配置出发

1、开启gzip压缩。

 

gzip on;
gzip_min_length 1000;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript;

 

2、配置html静态缓存

http下配置

 

 proxy_connect_timeout 600;
	proxy_read_timeout 600;
	proxy_send_timeout 600;
	proxy_buffer_size 16k;
	proxy_buffers 4 128k;
	proxy_busy_buffers_size  256k;    
	proxy_temp_file_write_size  1024k;	
	proxy_cache_path /tmp/proxy_cache levels=1:2 keys_zone=cache_one:200m inactive=30d max_size=2g;
	proxy_temp_path /tmp/proxy_cache/temp;

 

server下配置

location ~ .*\.html(.*)$ {
              proxy_pass http://127.0.0.1:8080;
              proxy_redirect off;
              proxy_set_header Host $host;
              proxy_cache cache_one;
              #对应状态缓存周期
              proxy_cache_valid 200 302 6h;
              proxy_cache_valid 301 12h;
              proxy_cache_valid any 1m;
              expires 4h;
              proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
              add_header Nginx-Cache "$upstream_cache_status";
        }

 

3、其他静态资源由nginx直接处理

 

location ~ ^/(.*)\.(js|css|jpg|jpeg|gif|png|ico)(.*)$ {
              #proxy_pass http://127.0.0.1:8080;
              #proxy_redirect off;
              #proxy_set_header Host $host;
              #proxy_cache cache_one;
              #proxy_cache_valid 200 302 30d;
              #proxy_cache_valid 301 1d;
              #proxy_cache_valid any 1d;
              #expires 30d;
              #proxy_ignore_headers "Cache-Control" "Expires" "Set-Cookie";
              #add_header Nginx-Cache "$upstream_cache_status";
	      root /usr/local/tomcat/webapps/ROOT;
	      #access_log off;
              expires 24h;
        }

4、tomcat后台处理其他动态请求

 

 

location / {
            proxy_pass http://127.0.0.1:8080;
            proxy_set_header        Host $host;
            proxy_set_header        X-Real-IP $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        }

tomcat乱码处理http://www.manongjc.com/article/34072.html

 

 

 

 

 

 

 

你可能感兴趣的:(java,nginx,java,nginx,tomcat,缓存,gzip)