I have the following configuration for my application example.com:
- Nginx as a reverse proxy to redirect traffic from port 80 to:
- Tomcat 7 where I deploy my JSF app, port 8080
- My xhtml files are mostly in the ROOT folder: /usr/local/tomcat7/webapps/ROOT
- But I have some files in a separate folder "forum": /usr/local/tomcat7/webapps/ROOT/forum
This is my default nginx configuration:
server {
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
server_name example.com.br;
root /usr/local/tomcat7/webapps/ROOT;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
}
}
So, to access the forum page I have to go to example.com/forum/forum.xhtml (forum.xhtml is the index)
Now, I'm trying to set a subdomain, forum.example.com, in nginx, that will point to the forum folder, keeping the URL. That is, I don't want ever to see the sufix "/forum/" in the URL. I want that the forum folder behaves as the root. So if the user tries forum.example.com/anotherPageFromROOT.xhtml he will not be able to.
This is what I have so far:
server {
listen 80;
server_name forum.example.com;
location / {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080/;
rewrite ^/$ /forum/forum.xhtml break;
}
}
Problems:
- If I click in a link (POST request) to the file "topic.xhtml" also inside the "forum" folder the URL will be forum.example.com/forum/topic.xhtml instead of forum.example.com/topic.xhtml as I want.
- The user is able to access forum.example.com/anotherPageFromROOT.xhtml normally
Could some one please help me on what I should do? Thanks!
EDIT:
I think the root cause for the first problem is the action
generated by JSF for my h:form
. It is always generated with /forum/
.
Copyright Notice:Content Author:「qxlab」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30769891/nginx-and-tomcat-subdomain-pointing-to-subdirectory