How to avoid Error 403 Forbidden : Apache virtual host configuration issue

apache-2.2jbossstatic-contentvirtualhost

I am quite a newbie to the Apache Server (2.0, I know it is a bit too old, however my workplace demands me to learn it as it is the version we are using)and now trying to get Apache work with Jboss (Jboss as the application server, Apache fronting JBoss and serving all the static content).

I have got Apache work with Jboss with the aid of mod_jk; however when I am trying to add virtual host configuration to get Apache to serve images from a specific folder instead of pushing JBoss to serve static content, I am getting 403 Forbidden error.

I went through several forums and other websites to digout an answer or a solution to this problem, sadly nothing seems to work for me! 🙁

Please can anyone help me with this? a little bit of explaining would be a welcoming addition.

The following is my virtual host definition in httpd.conf file.

<VirtualHost *:80>
ServerAdmin admin@localhost
ServerName localhost
DocumentRoot "D:/Dev-Ops/apache/Apache2/htdocs/jboss/"

<Directory "D:/Dev-Ops/apache/Apache2/htdocs/jboss/">
AllowOverride All
Order Allow,Deny
Allow from all
Require all granted
</Directory>

#rewrite incoming requests
RewriteEngine On
RewriteCond /SchoolApp%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ http://localhost:8080/SchoolApp/$1 [proxy,last]

</VirtualHost>

Your help will be much appreciated.

PS: I was following this Link after trying several other such instructions.

Best Answer

Finally I figured it out myself. Mod-Jk has JkMount and JkUnMount directives to accomplish redirection of content.

<VirtualHost *:80>

    ServerAdmin admin@localhost.com
    DocumentRoot "D:\Dev-Ops\apache\Apache2\htdocs"
    ServerName localhost.com

    JkMount /SchoolApp/* loadbalancer
    JkMount /SchoolApp loadbalancer
    JkUnMount /SchoolApp/*jpg loadbalancer
    JkUnMount /SchoolApp/*.html loadbalancer

</VirtualHost>

JkMount /SchoolApp/* redirects all the requests from Apache to the jboss web application SchoolApp (here : http://localhost.com:8080/SchoolApp/); since I have used
JkUnMount /SchoolApp/*jpg loadbalancer it will not redirect any requests for jpg files to jboss, instead it will look for SchoolApp/ folder under "D:\Dev-Ops\apache\Apache2\htdocs" and serve images from there, I have a proper directory structure under there that mimics the directory structure for the jpg file I have requested from the Jboss web application.

e.g. If I request for http://localhost.com/SchoolApp/, mod-jk redirects the request to http://localhost.com:8080/SchoolApp/ however; if I request for http://localhost.com/SchoolApp/welcome.jpg, this request will not be redirected to the http://localhost.com:8080/SchoolApp/welcome.jpg even if there is such a file under the jboss application, instead it will look for welcome.jpg under the htdocs/SchoolApp/ folder in apache and if welcome.jpg exists there, it will serve the file from there.

I hope this explains it.