
nginx反向代理结合tomcat
我直接贴代码吧
user www www; #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { # worker_connections 1024; use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #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; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; upstream tomcat { #server 127.0.0.1:8080; //第一个两个tomcat 解决tomcat重启的时候网站不能访问的问题 server 127.0.0.1:8081; //第二个tomcat 一个重启之后,另一个关闭 然后 nginx -s reload } gzip on; gzip_min_length 1k; gzip_buffers 4 16k; #gzip_http_version 1.0; gzip_comp_level 9; gzip_types image/x-icon text/plain application/x-javascript application/javascript font/woff2 text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary off; gzip_disable "MSIE [1-6]\."; #第1行:开启Gzip #第2行:不压缩临界值,大于1K的才压缩,一般不用改 #第3行:buffer,就是,嗯,算了不解释了,不用改 #第4行:用了反向代理的话,末端通信是HTTP/1.0,有需求的应该也不用看我这科普文了;有这句的话注释了就行了,默认是HTTP/1.1 #第5行:压缩级别,1-10,数字越大压缩的越好,时间也越长,看心情随便改吧 #第6行:进行压缩的文件类型,缺啥补啥就行了,JavaScript有两种写法,最好都写上吧,总有人抱怨js文件没有压缩,其实多写一种格式就行了 #第7行:跟Squid等缓存服务有关,on的话会在Header里增加"Vary: Accept-Encoding",我不需要这玩意,自己对照情况看着办吧 #第8行:IE6对Gzip不怎么友好,不给它Gzip了 server { listen 80; server_name www.developzhe.com; access_log logs/www.developzhe.com.access.log; location / { proxy_pass http://tomcat; proxy_redirect off; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host "www.developzhe.com"; } #error_page error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } include vhost/*.conf; } include extends/*.conf;