I understand that to redirect from port 80 to port 8080 I can use the Apache module mod_proxy,

I understand that I have to change "something" to be like this (example from http://httpd.apache.org/docs/2.2/mod/mod_proxy.html):

ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar 

What I don't understand is how do I "edit mod_proxy". I found a file called mod_proxy.so but it is not a text file that can be edited.

What do I have to do to make these changes, is it a text file somewhere I have to edit or some commands I have to run?


Based on this question How to use mod_proxy to let my index of Apache go to Tomcat ROOT and be able to browse my other Apache sites

I edited httpd.conf to look like this:

LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

#Enabling proxy for redirection to tomcat

#ProxyRequests Off

#ProxyPreserverHost On

<Proxy *>
Order deny, allow
Allow from all
#ProxyPass / ajp://localhost:8009/
#ProxyPassReverse / ajp://localhost:8009/

<Location http://www.mywebserver.com>
Order allow,deny
Allow from all
PassProxy / http://localhost:8080/
PassReverseProxy / http://localhost:8080

I then tried to restart apache with apachectl -k graceful but I got:

 Syntax error on line 207 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/httpd.conf: Cannot load /etc/apache2/modules/mod_proxy.so into server: /etc/apache2/modules/mod_proxy.so: cannot open shared object file: No such file or directory
Action '-k graceful' failed.

Any info on what I'm doing wrong or what I can read to get more info, would be much appreciated.

  • Check line 207 and paste it here. Might be you simply miss to restart after loading some new stuff (module). – Chris Dec 14 '11 at 9:32
  • I fixed that, but then got a different error, will try what you've suggested first and see if that changes things. – Ankur Dec 14 '11 at 10:11

What I normally do is first enable mod_proxy and mod_proxy_ajp. Depending on your distribution you a2enmod mod_proxy_ajp and it enables them both as ajp depends on mod_proxy.

Then I add something like this:

<IfModule mod_proxy_ajp.c>
  <Location /tomcat-context>
     ProxyPass ajp://IP-or-FQDN/tomcat-context
     ProxyReversePass ajp://IP-or-FQDN/tomcat-context

This part is placed inside my <VirtualHost>. The rest is basic configuration set by the OS (just like your configuration shows, with ProxyRequests Off etc.)

UPDATE: What you need to change, or at least verify is your tomcat server.xml. It must have the ajp-container enabled like this:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

You can disable the connector on 8080 if that is all you serve from tomcat and if you do not need the backend. In case you don't have access to this, or ports for ajp are disabled, you can basically achieve the same wirth 8080. Just replace the ajp:// tag in the provided configuration with http:// and add :8080 after IP-or-FQDN.

UPDATE 2 To serve / just write

<IfModule mod_proxy_ajp.c>
  <Location />
    ProxyPass ajp://IP-or-FQDN/tomcat-context
    ProxyReversePass ajp://IP-or-FQDN/tomcat-context

Ensure you comment out the DocumentRoot /path/to/old/documentroot/ directive and the <Directory /path/to/old/documentroot/> in your apache configuration.

  • Thanks for this ... it'll take me some time to try it out and digest it, will report back with results. – Ankur Dec 14 '11 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.