没有为单个 jboss 实例中具有相同上下文路径的多个 war 加载静态内容
Static content is not being loaded for multiple war with same context path inside single jboss instance
我在 jboss 4 中使用虚拟主机部署了两个具有相同上下文路径的 war STORE_ABC.war
和 STORE_DEF.war
文件。STORE_ABC.war
可通过以下方式访问URL http://localhost:8080/home
和 STORE_DEF.war
可通过 URL http://testsite1:8080/home
访问。server.xml
的配置如下所示。
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}"
redirectPort="${jboss.web.https.port}" />
<Connector port="8089" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="443"
protocol="AJP/1.3"/>
<Connector port="8445" address="${jboss.bind.address}"
maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
scheme="https" secure="true" clientAuth="false"
keystoreFile="${jboss.server.home.dir}/conf/bookstore.keystore"
keystorePass="bookstore" sslProtocol = "TLS" allowTrace="true"/>
<Engine name="jboss.web" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
/>
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
</Host>
<Host name="vhost2" autoDeploy="false"
deployOnStartup="false" deployXML="false">
<Alias>testsite1</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="vhost2" suffix=".log" pattern="common"
directory="${jboss.server.home.dir}/log"/>
<DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>
</Engine>
</Service>
</Server>
STORE_ABC.war
的jboss-web.xml
<jboss-web>
<context-root>/</context-root>
</jboss-web>
STORE_DEF.war
的jboss-web.xml
<jboss-web>
<context-root>/</context-root>
<virtual-host>testsite1</virtual-host>
</jboss-web>
我在 jboss 的 deploy
文件夹中有第三个 static.war
与 STORE_ABC.war
和 STORE_DEF.war
平行,用于提供静态内容(css
和 images
)。
现在的问题是来自 static.war
的静态内容没有被加载到 STORE_DEF.war
而它在 STORE_ABC.war
.
上工作正常
我自己发现问题出在 static.war
。我需要在 static.war
中创建一个文件夹 WEB-INF
并放置一个 jboss-web.xml
如下:
<jboss-web>
<context-root>/static</context-root>
<virtual-host>testsite1</virtual-host>
<virtual-host>localhost</virtual-host>
</jboss-web>
并且需要在 STORE_ABC.war
的 jboss-web.xml
中进行更正
<jboss-web>
<context-root>/</context-root>
<virtual-host>localhost</virtual-host>
</jboss-web>
完成上述所有更改后,它开始正常工作。
我在 jboss 4 中使用虚拟主机部署了两个具有相同上下文路径的 war STORE_ABC.war
和 STORE_DEF.war
文件。STORE_ABC.war
可通过以下方式访问URL http://localhost:8080/home
和 STORE_DEF.war
可通过 URL http://testsite1:8080/home
访问。server.xml
的配置如下所示。
<Server>
<Service name="jboss.web"
className="org.jboss.web.tomcat.tc5.StandardService">
<Connector port="8080" address="${jboss.bind.address}"
maxThreads="250" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
enableLookups="false" redirectPort="443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true"/>
<Connector protocol="HTTP/1.1" port="8081" address="${jboss.bind.address}"
redirectPort="${jboss.web.https.port}" />
<Connector port="8089" address="${jboss.bind.address}"
emptySessionPath="true" enableLookups="false" redirectPort="443"
protocol="AJP/1.3"/>
<Connector port="8445" address="${jboss.bind.address}"
maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
scheme="https" secure="true" clientAuth="false"
keystoreFile="${jboss.server.home.dir}/conf/bookstore.keystore"
keystorePass="bookstore" sslProtocol = "TLS" allowTrace="true"/>
<Engine name="jboss.web" defaultHost="localhost">
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
/>
<Host name="localhost"
autoDeploy="false" deployOnStartup="false" deployXML="false">
</Host>
<Host name="vhost2" autoDeploy="false"
deployOnStartup="false" deployXML="false">
<Alias>testsite1</Alias>
<Valve className="org.apache.catalina.valves.AccessLogValve"
prefix="vhost2" suffix=".log" pattern="common"
directory="${jboss.server.home.dir}/log"/>
<DefaultContext cookies="true" crossContext="true" override="true"/>
</Host>
</Engine>
</Service>
</Server>
STORE_ABC.war
的jboss-web.xml
<jboss-web>
<context-root>/</context-root>
</jboss-web>
STORE_DEF.war
的jboss-web.xml
<jboss-web>
<context-root>/</context-root>
<virtual-host>testsite1</virtual-host>
</jboss-web>
我在 jboss 的 deploy
文件夹中有第三个 static.war
与 STORE_ABC.war
和 STORE_DEF.war
平行,用于提供静态内容(css
和 images
)。
现在的问题是来自 static.war
的静态内容没有被加载到 STORE_DEF.war
而它在 STORE_ABC.war
.
我自己发现问题出在 static.war
。我需要在 static.war
中创建一个文件夹 WEB-INF
并放置一个 jboss-web.xml
如下:
<jboss-web>
<context-root>/static</context-root>
<virtual-host>testsite1</virtual-host>
<virtual-host>localhost</virtual-host>
</jboss-web>
并且需要在 STORE_ABC.war
jboss-web.xml
中进行更正
<jboss-web>
<context-root>/</context-root>
<virtual-host>localhost</virtual-host>
</jboss-web>
完成上述所有更改后,它开始正常工作。