Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to forward a port from 80 to 8080 (default to tomcat). below is what I added to the httpd file.

 <VirtualHost www.example.com:80> 
      ProxyPreserveHost On
      ProxyRequests Off
      ServerName www.example.com
      ServerAlias example.com
      ProxyPass / http://localhost:8080/
      ProxyPassReverse / http://localhost:8080/
    </VirtualHost>

After adding this , there are no signs of any change. Is there anything wrong with the code?
Centos 5.9
apache 2.2
tomcat 7
whm/cpanel.

UPDATE: enter image description here My target domain is www.99rounds.com:80 direct to :8080

Update 2 After added the code from the answer, and removing the 2 lines of logs. I get: enter image description here Note that centos has built-in mod_proxy support, if I force it : loadModule ... It will give me the error saying its built in.

share|improve this question
    
Yes, that will probably be inactive when added to most default configs. Can you provide your existing configuration, and the output of apachectl -S? –  Shane Madden Mar 4 '13 at 3:37
    
@ShaneMadden got it updated. –  wtsang02 Mar 4 '13 at 3:50
    
There's config for the www version of the name in /usr/local/apache/conf/includes/post_virtualhost_global.conf and the non-www version in /usr/local/apache/conf/httpd.conf, probably with ServerAlias directives binding them to the other name -- which one of these is the one you added the configuration to? –  Shane Madden Mar 4 '13 at 4:37
    
post_virtualhost_global.confGlobal I added the below code from answer but still no forwarding. –  wtsang02 Mar 4 '13 at 16:11

2 Answers 2

up vote 4 down vote accepted

I have a detailed answer on how I have setup Apache Reverse Proxy over here.

Looking at the configuration you provide:

<VirtualHost www.example.com:80> 
  ProxyPreserveHost On
  ProxyRequests Off
  ServerName www.example.com
  ServerAlias example.com
  ProxyPass / http://localhost:8080/
  ProxyPassReverse / http://localhost:8080/
</VirtualHost>

I would suggest the following instead. I am presuming some things—such as ErrorLog & CustomLog—but this is how I would set things up. The key I believe is the ServerName & ServerAliascombined with the <VirtualHost *:80>:

<VirtualHost *:80>
  ServerName www.99rounds.com
  ServerAlias 99rounds.com www.99rounds.com

  ErrorLog /var/log/apache2/www.99rounds.com.error.log
  CustomLog /var/log/apache2/www.99rounds.com.access.log combined

  # Settings for Apache Reverse Proxy
  <IfModule mod_proxy.c>

    # Proxy specific settings
    ProxyRequests Off
    ProxyPreserveHost On

    <Proxy *>
      AddDefaultCharset off
      Order deny,allow
      Allow from all
    </Proxy>

    ProxyPass / http://localhost:8080/ 
    ProxyPassReverse / http://localhost:8080/ 

  </IfModule>

</VirtualHost>

EDIT: Also be sure you have mod_proxy and mod_proxy_http enabled on your server:

sudo a2enmod proxy
sudo a2enmod proxy_http
share|improve this answer
    
a2enmod doesn't work on centos. And I have updated the question with your solution. –  wtsang02 Mar 4 '13 at 16:18
1  
This has nothing to do with port forwarding or CentOS and everything to do with Apache2 virtual host configuration. The error that is key is "VirtualHost :80 -- mixing * ports and non- ports with a NameVirtualHost address is not supported, proceeding with undefined results" Which basically means you have some virtual hosts set to an ip address "1.2.3.4:80" and then in the example I give it's "*:80" So perhaps you should use my example, but change the config to read: <VirtualHost your.domain.com:80> or <VirtualHost 1.2.3.4:80> with your.domain.com being your domain or 1.2.3.4 being your IP. –  JakeGould Mar 4 '13 at 17:25
    
I was just about to update. That I fixed the * issue by defining the star to domain. Ill update the post in 1min. –  wtsang02 Mar 4 '13 at 17:28
1  
I added this to pre_virtualhost_global.confGlobal and it worked. Before it was at post_virtualhost_global.confGlobal. I would +100 if I can. –  wtsang02 Mar 5 '13 at 1:01
    
Happy this worked out for you! Apache virtual host configs can be confusing. If you can, I would recommend that you setup a clean test server & experiment with differed named virtual host configs. –  JakeGould Mar 5 '13 at 2:31

Tomcat and other application servers publish an AJP port that can be used to map request from a HTTP server. To do that you have to create a 'workers files' like this:

# server.workers.properties

worker.list=tomcat-server

worker.tomcat-server.type=ajp13
worker.tomcat-server.host=localhost
worker.tomcat-server.port=8009

8009 is the default value for the AJP port in a Tomcat server. You can find this value in $TOMCAT_DIR$/conf/server.xml. Then you have to indicate the previous file in the HTTP configuration file:

JkWorkersFile /location/of/the/file/server.workers.properties

<VirtualHost www.example.com:80> 
  ServerName www.example.com
  ServerAlias example.com
  DocumentRoot /srv/www/
  JkMount /* tomcat-server 

  <Directory />
    Options +FollowSymLinks
    Order allow,deny
    Allow from all
  </Directory>

</VirtualHost>

This configuration will pass all requests by www.example.com:80 to the AJP 8009 port, so the Tomcat server will get those requests and it will process them.

In the path set in DocumentRoot you have to put the links for each application in Tomcat's webapps directory because if you don't do that, the HTTP server will not be able to load resource files, like CSS and JS.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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