Nginx 代理 Tomcat 问题
下面两种方案,不知道是不是我什么地方配置不对还是什么,第一种配置后,非常消耗资源,特别第一次启动
Tomcat
,基本的启动不了,第二种就没问题,但是第二种有一个问题就是如果是
我访问
http://kaipizhe.com
这个时候
request.getRequestURI();
这个值是
/kaipizhe/
而不是
/
我访问
http://kaipizhe.com/all/
这个时候
request.getRequestURI();
这个值是
/kaipizhe/all/
而不是
/all/
具体看这个问题: 链接描述
方案一:
Nginx
配置:
nginx
server { listen 80; server_name kaipizhe.com; root /usr/local/tomcat/webapps/kaipizhe; include none.conf; location / { proxy_pass http://localhost:8080/; proxy_cookie_path / /; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect http://localhost:8080/ http://kaipizhe.com/; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/kaipizhe.com.log kaipizhe.com; }
Tomcat
server.xml
配置:
xml
<Host name="kaipizhe.com" appBase="kaipizhe" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false"> <alias>kaipizhe.com</alias> <Context docBase="/usr/local/tomcat/webapps/kaipizhe" path="/" reloadable="true" /> </Host>
方案二:
Nginx
配置:
nginx
server { listen 80; server_name kaipizhe.com; root /usr/local/tomcat/webapps/kaipizhe; include none.conf; location / { proxy_pass http://localhost:8080/kaipizhe/; proxy_cookie_path /kaipizhe /; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_redirect http://localhost:8080/kaipizhe/ http://kaipizhe.com/; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; } access_log /home/wwwlogs/kaipizhe.com.log kaipizhe.com; }
Tomcat
server.xml
不修改,也就是不增加
Host
比利.海灵顿
9 years, 8 months ago