简体   繁体   中英

Issue loading resources using mod_jk with httpd and tomcat

I have a tomcat application. I am also using apache server and connected it to tomcat using mod_jk. Here I used rewrite module to change my url and but when my website is running, page resources (css, js) are not loading correctly.

My tomcat application name Mahmudul . I want to make the url www.mahmudul.com , so I configured httpd.conf file. here is my configurtion.

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

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

If I configured the URL to load from www.mahmudul.com/Mahmudul , not everything works fine because then resources location is /assets/css/styles/ . But I changed the above configuration to make the URL www.mahmudul.com . but now the location of resources /Mahmudul/assets/css/styles/ and resources are not loading. Also when clicking any links such as "contact", link shows "/Mahmudul/contact" and also session id is attached with the links. I want to omit /Mahmudul . How can I do this?

I have solved this issue. Here I didn't have to rewrite URL. I used the same virtual host configuration but without RewriteEngine. I just needed to configure tomcat server.xml and added a new host configuration. Here is configuration-

<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>

Here is my worker.properties

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

And my apache httpd.conf virtual host configuration

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

I hope it helps. Thank you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM