使用 mod_jk 与 httpd 和 tomcat 发布加载资源

Issue loading resources using mod_jk with httpd and tomcat

我有一个 tomcat 应用程序。我也在使用 apache 服务器并使用 mod_jk 将其连接到 tomcat。在这里,我使用重写模块来更改我的 url,但是当我的网站是 运行 时,页面资源(css、js)没有正确加载。

我的 tomcat 应用程序名称 Mahmudul。我想制作 url www.mahmudul.com,所以我配置了 httpd.conf 文件。这是我的配置。

<VirtualHost *:80>
 ServerName www.mahmudul.com

 RewriteEngine on
 RewriteRule ^/(.*)$ /Mahmudul/ [l,PT]
 JkMount /* tomcat1
</VirtualHost>

如果我将 URL 配置为从 www.mahmudul.com/Mahmudul 加载,并非一切正常,因为资源位置是 /assets/css/styles/。但是我把上面的配置改成了URLwww.mahmudul.com。但是现在资源的位置 /Mahmudul/assets/css/styles/ 和资源都没有加载。此外,当单击任何 link 时,例如 "contact",link 会显示“/Mahmudul/contact”,并且会话 ID 会附加到 link 中。我想省略 /Mahmudul。我怎样才能做到这一点?

我已经解决了这个问题。在这里我不必重写 URL。我使用了相同的虚拟主机配置,但没有使用 RewriteEngine。我只需要配置 tomcat server.xml 并添加一个新的主机配置。这是配置-

<Host name="mahmudul.com" appBase="webapps" unpackWARs="true" autoDeploy="true">
    <Alias>www.mahmudul.com</Alias>
    <Context path="" docBase="Mahmudul-1.0-SNAPSHOT" debug="0" privileged="true" />
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>

这是我的worker.properties

worker.list=tomcat1
worker.tomcat1.type=ajp13
worker.tomcat1.port=8009
worker.tomcat1.host=localhost

还有我的apachehttpd.conf虚拟主机配置

<VirtualHost *:80>
        ServerName mahmudul.com
        ServerAlias www.mahmudul.com
        JkMount /* tomcat1
</VirtualHost>

希望对您有所帮助。谢谢。