views:

800

answers:

1

I have two sub domains that are located on different ports.

  1. www.myexample.com locates on port 83
  2. blog.myexample.com locates on port 82

I have done the following to my Apache configuration file:

httpd.conf I incude three conf files, proxyserver.conf, mainhtml.conf and sidehtml.conf

The content of proxyserver.conf is

    NameVirtualHost *:80    
    <VirtualHost *:80>
      ServerName www.myexample.com
      ProxyPass               /       http://localhost:83/
      ProxyPassReverse        /       http://localhost:83/
    </VirtualHost>      
    <VirtualHost *:80>
      ServerName blog.myexample.com
      ProxyPass               /       http://localhost:82/
      ProxyPassReverse        /       http://localhost:82/   
</VirtualHost>

The content of mainhtml.conf is

  Listen *:83
  NameVirtualHost *:83  
  <VirtualHost *:83 >
    ServerName www.myexample.com
    DocumentRoot "C:\Documents and Settings\test\My Documents\mainhtml"
    DirectoryIndex index.html index.php
    <Directory  "C:\Documents and Settings\test\My Documents\mainhtml">
       AddDefaultCharset UTF-8
       AllowOverRide none
       Options FollowSymlinks
       Order allow,deny
       Allow from all
       RewriteEngine on
       RewriteRule ^.*/(.*)$ sysGeneric.php [NC,L]
    </Directory>
  </VirtualHost>

The content of sidehtml.conf is

 Listen *:82
 NameVirtualHost *:82
 <VirtualHost *:82 >
    ServerName blog.myexample.com
    DocumentRoot "C:\Documents and Settings\test\My Documents\sidehtml"
    DirectoryIndex index.html index.php
    <Directory  "C:\Documents and Settings\test\My Documents\sidehtml">
       AddDefaultCharset UTF-8
       AllowOverRide none
       Options FollowSymlinks
       Order allow,deny
       Allow from all
       RewriteEngine on
       RewriteRule ^.*/(.*)$ sysGeneric.php [NC,L]
    </Directory>
  </VirtualHost>

Besides that, I also enable the following in my httpd.conf file:

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
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

And also include the following line in my c:/windows/system32/drivers/etc/hosts file:

*my_ip_address* *.myexample.com

But after I restart my computer, when I type in www.myexample.com, I got directed to port 83, which means that the content of blog.myexample.com is shown. When I type in blog.myexample.com, I got redirected to an external websites.

What did I do wrong?

+1  A: 

Hi,

The Proxy directives are not supposed to redirect; you should never see port 82 or port 83 appear in your browser's address bar. If that happens then it is the PHP applications themselves that issue a HTTP 302 Redirect to localhost:82, which is not what you want. Many PHP applications have a configuration variable somewhere which you can change so that they redirect (when they redirect) to a custom URL, in this case www.example.com for one application and blog.example.com for the other.

Also, unrelated, I would recommend that you change Listen *:82 to Listen 127.0.0.1:82, so that the individual sites can only be accessed locally (by the reverse proxy or by you), and only through the reverse proxy when coming from the internet.

Also, do not use wildcards in the hosts file. Explicitly add:

127.0.0.1 www.example.com blog.example.com

Cheers, V.

vladr