Reputation: 5984
i have deployed a webapp on tomcat on digital ocean droplet
The structure of the war file is (Servelet is the webapp name)
Servelet
---- WEB-INF/classes/folder/FileXyz.class
Now on my local pc when i want to access this i do:
localhost:8080/Servelet/FileXyz
I deployed the same war on the tomcat on digital ocean but this time with a domain connected : server.foodini.co.in
Now i can access the same file using:
server.foodini.co.in:8080/Servelet/FileXyz
This works fine.
Now i wanted to have an nginx in front which would listen to the 80 port and forward all requests to the tomcat webapp via a reverse proxy
I edited the default file under /etc/nginx/sites-available under the server configuration, i added:
server_name server.foodini.co.in
root /opt/tomcat/webapps/Servelet
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/;
}
Now when i do
server.foodini.co.in
It opens the tomcat default page as expected
But
server.foodini.co.in/Servelet/FileXyz
(adding the port 8080 again works)
gives a 404 and the same 404 for all other paths, can someone please guide me.
Upvotes: 1
Views: 822
Reputation: 7742
You need to set the Host Header when passing the request to the proxied server, otherwise nginx will override the Host header with the variable $proxy_host, which in this case would be 127.0.0.1:8080
and you want it to be server.foodini.co.in:8080
. So just add this to the location /
block:
proxy_set_header Host $host:$proxy_port;
Upvotes: 1