If nginx
has the following configuration
I visit http://kaipizhe.com
At this time request.getRequestURI();
this value is /kaipizhe/
instead of /
When I visit http://kaipizhe.com/all/
this time request.getRequestURI();
the value is /kaipizhe/all/
instead of /all/
That is, request.getRequestURI();
will bring /kaipizhe/
, how to make it directly /
,
Is it me? nginx
There is a configuration problem, what should I do?
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; }
It is recommended to modify the configuration of tomcat, configure a virtual host for your project, and set the root directory of the project to /usr/local/tomcat/webapps/kaipizhe (or the actual root directory of your project), so that you do not need to add a / when accessing kaipizhe prefix, naturally the result obtained by request.getRequestURI() is also what you want.
If you use the above access, remember to modify the nginx configuration, it should be fine.
You can also implement it without modifying the tomcat configuration, adding a virtual host, or using nginx rewrite rules;