How to set context path in Tomcat so one could enter the site without appending the deployed folder name?

前端 未结 3 883
时光说笑
时光说笑 2021-01-04 11:38

I read about this on Tomcat guide here and some SO questions. And I think I\'m pretty much doing the same thing. But in some way cannot manage to succeed.

First of a

3条回答
  •  有刺的猬
    2021-01-04 12:16

    The Tomcat Wiki has a section on putting applications into default context. However, in order to do this it implies some control over the Tomcat server that may not be possible in the shared context you describe.

    If you have the ability to install other systems on the server, one alternate solution would be to use a proxy server like NGINX. This is way more complicated than simply naming your war file ROOT.war, but sometimes it's the only option.

    If you have NGINX listening on the server and you have your own url, you use the HttpProxyModule with setting such as:

    server {
            listen          80;
            server_name     my.domain.com;
            location / {
                proxy_pass              http://my-host/my-application;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        Host $http_host;
            }
        }
    

    Also in order to make this work, you'd have to own the "my.domain.com" url and it would need to be separate from the one everyone is using for the shared Tomcat server.

    The nginx portion of the solution is free, but if you need to register a new url and then use something like no-ip.com to redirect it to the tomcat server it would cost money.

提交回复
热议问题