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

1 Answer

up vote 3 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
add comment

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.