nginx+tomcat中server配置
一般利用nginx做代理,在nginx.conf中
?
?
server { listen 80; server_name localhost; root /home/mysite/public_html; location / { index index.html index.htm index.jsp; } location ~ .*.jsp$ { index index.jsp; proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } location ~ \.action$ { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } location ~ ^/WEB-INF/* { proxy_pass http://localhost:8080; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
这种方式需要服务器开两个端口,一是80,二是8080。
?
还有一种请求配置方法:
location ~ .*.[jsp|do|action]$ { #所有jsp页面以及do/action请求均交由tomcat处理????index index.jsp;????proxy_pass http://localhost:8080; #转向tomcat处理}location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { #设定访问静态文件直接读取不经过tomcat????expires????? 30d;}location ~ .*\.(js|css)?$ {????expires????? 1h;}