Tomcat host configuration server.xml

霸气de小男生 提交于 2019-12-12 22:23:23

问题


I have this web.xml in my application.

<web-app>
    <filter>
        <filter-name>app</filter-name>
        <filter-class>org.apache.tapestry5.spring.TapestrySpringFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>openSessionInView</filter-name>
        <url-pattern>/app/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>app</filter-name>
        <url-pattern>/app/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>app</filter-name>
        <url-pattern>/assets/*</url-pattern>
    </filter-mapping>


     <servlet>
        <servlet-name>jersey-serlvet</servlet-name>
        <servlet-class>
            com.sun.jersey.spi.spring.container.servlet.SpringServlet
        </servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.package.example.restServer</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
</web-app>

when I use my application in jetty works fine.

Web application:

http://localhost/app 

Api rest application:

http://localhost/rest

In produccion I use tomcat.

I want to create http://www.example.com -> http://localhost/app 

and http://rest.example.com -> http://localhost/rest

My server.xml file:

      <Host name="www.example.com" appBase="/usr/local/tomcat/webapps/example">
        <Context path="app" docBase="."/>
      </Host>


      <Host name="rest.example.com" appBase="/usr/local/tomcat/webapps/example">
        <Context path="rest" docBase="."/>
      </Host>

When I use this config, the server return a 404 error code.

How I can fix it?

Thanks.


回答1:


I got that error too and just couldn't fix for a couple of weeks but somehow i have remembered that i must check the hosts file in the C:\Windows\System32\drivers\etc. When i checked that i got shocked! Because the file was modified by another application that i installed on my machine and the 12.0.0.1 address were showing different urls and 0.0.0.0 was showing the local host.

If you see something like this too; either delete everything and just leave "127.0.0.1 localhost" or, use 0.0.0.0 when making your tests on your local machine.

I hope this helps.



来源:https://stackoverflow.com/questions/12271095/tomcat-host-configuration-server-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!