0

I am using linux server with CentOS 7,Apache 2.4.23 with mod jk installed. mod jk is installed and configured properly which opens the site but its not loading the css of that site.

I have tried various rewrite rules too but the problem remains same.

below are the configurations which I have used in my httpd.conf for mod_jk

RewriteRule ^/(.*)$ /test/$1 [PT]

JkMount /* test

worker.properties:

worker.list=test 

worker.test.type=ajp13 
worker.test.host=localhost 
worker.test.port=8009 

all mod_jk configurations are in httpd.conf and CSS is in Tomcat

no any changes has been made in context file of Tomcat.

server.xml

shutdown port = 8005
http port = 8080
ajp port = 8009

Thanks

Dushyant Gohil
  • 67
  • 1
  • 12
  • 1
    You should provide more info, specially the context of the Tomcat app, the location where the css is (is it served directly by apache or it also should be redirect to Tomcat?) Also provide your workers.properties file and all the mod_jk configuration in the httpd.conf or derived – jlumietu Dec 19 '16 at 12:21
  • workers.properties file worker.list=test worker.test.type=ajp13 worker.test.host=localhost worker.test.port=8009 all mod_jk configurations are in httpd.conf and CSS is in Tomcat – Dushyant Gohil Dec 20 '16 at 11:17
  • Is difficult to state what happens only with this data. Please provide info about the tomcat app context (it seems to be `/test/`) and the url (straight tomcat and through apache and mod_jk) of one of the css file wich is failing – jlumietu Dec 20 '16 at 11:23
  • httpd.conf details are as below RewriteRule ^/(.*)$ /test/$1 [PT,L] JkMount /* test – Dushyant Gohil Dec 20 '16 at 11:27
  • It is impossible to say why a url is failing if you don't tell us the url. – jlumietu Dec 20 '16 at 11:34
  • i am accessing it over lan, so I have used servername in my httpd.conf as server.com – Dushyant Gohil Dec 20 '16 at 11:39
  • This seems a kind of riddle game. I suppose that the css file (or files) have a kind of url like this: `/test/style.css`. So, if you go straight to tomcat, the url should be more or less like this: `http://localhost:8080/test/style.css`. I suppose that the css is in fact getting returned if you go this way. If so, the url through Apache and mod_jk should be `http://server.com/test/style.css`, and this is which does not load. Please confirm all theese guesses are correct and otherwise tell the correct statements. – jlumietu Dec 20 '16 at 11:48
  • yes you are correct that's the exact thing which I am facing. – Dushyant Gohil Dec 20 '16 at 11:50

3 Answers3

1

You cannot access your css because the link is incorrect.

According to your project structure, your css is in: project_root/webapp/resources/style.css, and the link to access it should be http://[host:port]/resources/style.css.

Instead of this, you are typing your css url as:

"${pageContext.request.contextPath}/resources/css/style.css"

where it should be:

"${pageContext.request.contextPath}/resources/style.css"

If you change this param in your css link I bet it would be returned as expected.

Other thing is the convenience or not of serving the css, js and other static stuff straight from Apache Httpd (or any other web server) instead of from Tomcat. There are different oppinions on it, specially if you provide Apache APR libraries to Tomcat. I personally prefer it. In this case, once after you copied/moved/redirect via alias your static elements to Apache, your JKMount strategy should be more complex. This could be one approach:

JkMount /test/* test
JkUnMount /test/resources/* test

EDIT:

I've been looking again to your config and I finally realized that the problem is in fact the RewriteRule you are using.

What RewriteRule ^/(.*)$ /test/$1 [PT] actually does is rewrite every request to that host (or virtual host) so adding an additional /test/ context path to the beginning of the request path.

It works OK for the first request, so that it takes the http://server.com/ request and rewrites it to http://server.com/test/. After it the JKMount redirects the request to the tomcat, as it redirects every mach to test worker and as you are applying a universal expression (/*) every request gets redirected to tomcat.

So, the first request does like this:

http://server.com/ > http://server.com/test/

But any subsequent resource or link (including css resources) within you Tomcat app will actually have the /test/ context correctly setted (at least the css you are trying to load). So, the css link /test/resources/css/style.css get rewrited too, and it ends this way: /test/test/resources/css/style.css which is an incorrect url.

Now, to avoid it, my suggestion is to change your RewriteRule to only manage the call to root element, this way:

RewriteRule ^/$ /test/ [PT]

If you do it like this, just the initial request to http://server.com/ will be rewritten to http://server.com/test, and any subsequent resource, link or form action, as your whole application is managed by spring mvc, will already have the /test context path mapping in the uri

jlumietu
  • 6,234
  • 3
  • 22
  • 31
0

Add all your html, images and css folders in apache server and your java classes in tomcat/webapps/project/WEB-INF/classes and all will start working fine

Ghayel
  • 1,113
  • 2
  • 10
  • 19
  • that works but is that possible to make it directly accessible from tomcat? – Dushyant Gohil Dec 21 '16 at 10:59
  • @DushyantGohil Yes, it is possible and should work without doing anything more than you did before. But it is difficult to state anything more if you don't provide us your project structure and the exact css url's which don't work – jlumietu Dec 22 '16 at 07:56
  • I have posted details – Dushyant Gohil Dec 22 '16 at 09:15
  • @DushyantGohil the main purpose of the mod_jk is to render html, js, css, images, html or any other static contents from apache server and java files + libraries from tomcat. In this way there is speed that raise the efficiency of displaying contents. You can access static contents from tomcat by providing port number at the end of your domain e.g. http://127.0.0.1:8080/css/style.css – Ghayel Dec 22 '16 at 11:47
0

This is Project Structure

enter image description here

link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/style.css" type="text/css"

Dushyant Gohil
  • 67
  • 1
  • 12