Tomcat 主机配置 server.xml [英] Tomcat host configuration server.xml

查看:51
本文介绍了Tomcat 主机配置 server.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有这个 web.xml.

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.

网络应用程序:

http://localhost/app 

API 休息应用:

http://localhost/rest

在生产中我使用 tomcat.

In produccion I use tomcat.

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

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

我的 server.xml 文件:

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>

当我使用这个配置时,服务器返回一个 404 错误代码.

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

我该如何解决?

谢谢.

推荐答案

我也遇到了那个错误,几个星期都无法修复,但不知何故我记得我必须检查 C:\Windows\System32\驱动程序\等.当我检查时,我震惊了!因为文件被我安装在我机器上的另一个应用程序修改了,12.0.0.1 地址显示不同的 url,0.0.0.0 显示本地主机.

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.

如果你也看到类似的东西;要么删除所有内容并保留127.0.0.1 localhost",或者在本地计算机上进行测试时使用 0.0.0.0.

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.

我希望这会有所帮助.

这篇关于Tomcat 主机配置 server.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆