如果 nginx 下面这样的配置
我访问 http://kaipizhe.com 这个时候 request.getRequestURI(); 这个值是 /kaipizhe/ 而不是 /
我访问 http://kaipizhe.com/all/ 这个时候 request.getRequestURI(); 这个值是 /kaipizhe/all/ 而不是 /all/
就是 request.getRequestURI(); 都会带上 /kaipizhe/ ,怎么让他直接是 / ,
是不是我 nginx 配置有问题,应该怎么处理
log_format kaipizhe.com '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
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的配置,为你项目配置虚拟主机,把项目的根目录设置为 /usr/local/tomcat/webapps/kaipizhe (或者你项目实际的根目录),这样你访问就不需要加一个 /kaipizhe 前缀了,自然 request.getRequestURI() 获取的结果也是你想要的。
记得还是要修改一下 nginx 的配置
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/;
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。