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

前端 未结 3 884
时光说笑
时光说笑 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.

    0 讨论(0)
  • 2021-01-04 12:27

    Usually this can be achieved by the following steps:

    • Define a ROOT.xml context file in conf/Catalina/localhost
    • Name your webapp WAR “ROOT.war” or containing folder “ROOT”

    However, i doubt you will be able to do that on a shared Tomcat instance. Only one application can run as the default application. The hosting company will probably not allow it as otherwise which application will they allow to be the default out of the many people sharing the same Tomcat instance?

    See this link : http://staraphd.blogspot.com/2009/10/change-default-root-folder-in-tomcat.html

    0 讨论(0)
  • 2021-01-04 12:36

    In your question, you state that the admin set the context as:

    <Context path="" docBase="path of my-application deployed folder"/>
    

    Based on the comments above, I would suggest trying to use the relative path of your application rather than the absolute path.

    I tried this on my tomcat server with:

    <Context path="/" docBase="my-application/" />
    

    and that did the trick.

    The Host element which contains the Context element does actually set some parameters that might also impact the context. If it's the default settings, then a relative context should simply point to the webapps folder. If it's been changed, the results may vary.

    0 讨论(0)
提交回复
热议问题