1

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.

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

12 Comments

Perfect, yep, that's what it was... Was stuck for like a whole day man, you saved my ass... Thanks
Any idea how i can stop just the default server.foodini.co.in from showing the tomcat page?
You mean the default tomcat page on root / ?
Yea the root index.jsp .... This tomcat is just the backend access layer... No gui component.... Is there a way to redirect the index to say another domain?
You can do an exact match on nginx location = / or location = /index.jsp etc, then do a redirect. nginx.org/en/docs/http/ngx_http_core_module.html#location, bjornjohansen.no/nginx-redirect
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.