Link to home
Start Free TrialLog in
Avatar of larry718
larry718

asked on

virtual host - 1 static ip

Hi Experts,

I have apache 1.3.20, 1 static IP, 1 SMC Router, 5 servers (2-Redhat7.1, win98, winNT, win2k) and 10+ domain names (Domain1.com, Domain2.com & Domain3.com...)

Currently, I figure out how to set up a virtualhost to use apache to serve all the domains on 1 server.  What I really want to do is set up 1 Redhat7.1 Linux server to take care of the virtualhosting and redirect the request for the domain to the proper server.

SMC Router points Static IP of Port 80 to the Main Redhat 7.1 Linux.  So I would like my intranet architecture to be like this:

-Main RH7.1 Linux Server running Apache = domain1.com, domain2.com
-Rh7.1 Linux Server running Apache = domain3.com, domain4.com
-Win98 running Personal WebServer = domain5.com domain6.com
-WinNT running IIS4 = domain7.com, domain8.com
-Win2k running Apache Web Server = domain9.com, domain10.com

Thanks in advance for any assistance.
Avatar of ahoffmann
ahoffmann
Flag of Germany image

on the server managing your virtual hosts, do in httpd.conf:

  PorxyPass /someDir http://host.domain1.com/someOtherDir
  PorxyPassReverse /someDir http://host.domain1.com/someOtherDir

# never tested this, but should work ;-)
Avatar of larry718
larry718

ASKER

I am a newbie at apache.  ahoffmann, I've tried this but can't get it to work. Can you elaborate?
I am a newbie at apache.  ahoffmann, I've tried this but can't get it to work. Can you elaborate?
larry718,

You have one static IP, and what happened to the rest of the machine - how do to connect to each other.  I presume that they all are on the private IP range.  Perhaps the 192.168.x.x subnets.  And the machine that has apache running will be on both network public and private?

If this is the setup, what you could do it that, you need to get the DNS properly configured for the public internet - register the www.domain(1..9).com to point to your ONLY static IP.  and on that machine, you need to run apache with virtual hosting enable.  Configure the apache to virtual-host all the domain(1..9).com, and for each vhost, cache it from the internal server.

Look at the config below.  I believe it should work.  

----- excerpt from httpd.conf
#
#NameVirtualHost *

#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
#<VirtualHost *>
#    ServerAdmin webmaster@dummy-host.example.com
#    DocumentRoot /www/docs/dummy-host.example.com
#    ServerName dummy-host.example.com
#    ErrorLog logs/dummy-host.example.com-error_log
#    CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

NameVirtualHost 1.2.3.4


# This is for the server 1 which has internal Ip of 192.168.1.1

<VirtualHost 1.2.3.4>
    ServerName www.domain1.com
    ServerAdmin webmaster@domain1.com
    DocumentRoot /usr/local/apache/htdocs-domain1
    ErrorLog logs/domain1-error_log
    CustomLog logs/domain1_access_log common
      ProxyRequests On
   
      <Directory proxy:*>
         Order deny,allow
         Deny from all
         Allow from 10.1.35.200
#
#      Allow from all
      </Directory>
      ProxyVia On  
      CacheRoot "/usr/local/apache/proxy"
      CacheSize 5
      CacheGcInterval 4
      CacheMaxExpire 24
      CacheLastModifiedFactor 0.1
      CacheDefaultExpire 1
#     NoCache a_domain.com another_domain.edu joes.garage_sale.com
      ProxyPass        /       http://192.168.1.1
      ProxyPassReverse /       http://192.168.1.1
    </IfModule>
</VirtualHost>

# This is for the server 2 which has internal Ip of 192.168.1.2

<VirtualHost 1.2.3.4>
    ServerName www.domain2.com
    ServerAdmin webmaster@domain2.com
    DocumentRoot /usr/local/apache/htdocs-domain2
    ErrorLog logs/domain2-error_log
    CustomLog logs/domain2_access_log common
      ProxyRequests On
   
      <Directory proxy:*>
         Order deny,allow
         Deny from all
         Allow from 10.1.35.200
#
#      Allow from all
      </Directory>
      ProxyVia On  
      CacheRoot "/usr/local/apache/proxy"
      CacheSize 5
      CacheGcInterval 4
      CacheMaxExpire 24
      CacheLastModifiedFactor 0.1
      CacheDefaultExpire 1
#     NoCache a_domain.com another_domain.edu joes.garage_sale.com
      ProxyPass        /       http://192.168.1.2
      ProxyPassReverse /       http://192.168.1.2
    </IfModule>
</VirtualHost>
samri gave the example.
I'm just wondering about the
    Allow from 10.1.35.200
Also the Cache* directives need to be adapted to your requirements.
Yes, I have 1 static IP that is set to hit my router which redirects it to my Main Redhat 7.1 Linux Server.
ALL of my machines reside on a private network using 192.168.xxx.xxx.

Here's the apache httpd.conf I have:

NameVirtualHost 192.168.bb.aa   ===> internet static IP.
<VirtualHost 192.168.bb.aa>     ===> Private network Static IP.
        ServerName www.domain1.com
        ServerAdmin webmaster@domain1.com
        DocumentRoot /usr/local/apache/htdocs/www/domain1
        ErrorLog /usr/local/apache/logs/www/domain1.com-error_log
        CustomLog /usr/local/apache/logs/www/domain1.com-access_log common

        <IfModule mod_proxy.c>
        ProxyRequests On

        <Directory proxy:*>
                Order deny,allow
                Deny from all
                Allow from all
        </Directory>

        ProxyVia On
        CacheRoot "/usr/local/apache/proxy"
        CacheSize 5
        CacheGcInterval 4
        CacheMaxExpire 24
        CacheLastModifiedFactor 0.1
        CacheDefaultExpire 1
#       NoCache a_domain.com another_domain.edu
        ProxyPass     /       http://192.168.bb.aa
        ProxyPassReverse     /    http://192.168.bb.aa
        </IfModule>
</VirtualHost>

=====================================================

> [root@localhost bin]# pwd
/usr/local/apache/bin
[root@localhost bin]# ./apachectl configtest
[Mon Sep  3 22:05:03 2001] [alert] httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
Syntax OK
[root@localhost bin]# ./apachectl startssl
[Mon Sep  3 22:05:16 2001] [alert] httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
./apachectl startssl: httpd could not be started
[root@localhost bin]#

=====================================================
Can't get this one to work so I didn't add more VirtualHosts to it.
Goosh, I am reading up on this proxy stuff.  It sure is alot of material to understand.
Also I am wonderring about

Ahoffman's comment, what's  Allow from 10.1.35.200?
Also I am wonderring about

Ahoffman's comment, what's  Allow from 10.1.35.200?
Avatar of The--Captain
Pretty sure the problem lies here

"VirtualHost 192.168.bb.aa"

That needs to be a name (i.e. www.blah.com), IIRC, if you want apache to use name-based virtual hosts.  

Just add www.blah.com to /etc/hosts with the proper internal IP and you should be good to go.

-Jon

Hi,

Jon: your suggestion, I have implemented, I've in httpd.conf:

NameVirtualHost 192.aaa.bbb.ccc
NameVirtualHost 192.aaa.bbb.ddd

<VirtualHost www.domain111.com>
        ServerName www.domain111.com
        ServerAdmin webmaster@domain111.com
        DocumentRoot /usr/local/apache/htdocs/www/domain111
ErrorLog /usr/local/apache/htdocs/www/logs/domain111.com-error_log
        CustomLog /usr/local/apache/htdocs/www/logs/domain111.com-access_log common

        <IfModule mod_proxy.c>
        ProxyRequests On

        <Directory proxy:*>
                Order deny,allow
               Deny from all
                Allow from all
        </Directory>

        ProxyVia On
        CacheRoot "/usr/local/apache/proxy"
        CacheSize 5
        CacheGcInterval 4
        CacheMaxExpire 24
        CacheLastModifiedFactor 0.1
        CacheDefaultExpire 1
        NoCache a_domain.com another_domain.edu
        ProxyPass               /       http://192.aaa.bbb.ccc
        ProxyPassReverse        /       http://192.aaa.bbb.ccc
        </IfModule>
</VirtualHost>

<VirtualHost www.domain222.com>
        ServerName www.domain222.com
        ServerAdmin webmaster@domain222.com
        DocumentRoot /usr/local/apache/htdocs/www/domain222
ErrorLog /usr/local/apache/htdocs/www/logs/domain222.com-error_log
        CustomLog /usr/local/apache/htdocs/www/logs/domain222.com-access_log common

        <IfModule mod_proxy.c>
        ProxyRequests On

        <Directory proxy:*>
                Order deny,allow
               Deny from all
                Allow from all
        </Directory>

        ProxyVia On
        CacheRoot "/usr/local/apache/proxy"
        CacheSize 5
        CacheGcInterval 4
        CacheMaxExpire 24
        CacheLastModifiedFactor 0.1
        CacheDefaultExpire 1
        NoCache a_domain.com another_domain.edu
        ProxyPass               /       http://192.aaa.bbb.ddd
        ProxyPassReverse        /       http://192.aaa.bbb.ddd
        </IfModule>
</VirtualHost>


/etc/hosts file:
=======================================
#IP           FQDN               aliases
127.0.0.1     localhost
192.aaa.bbb.ccc     www.domain111.com     domain111
192.aaa.bbb.ddd     www.domain222.com     domain222

Output of ./apachectl configtest
==================================
[root@www bin]# ./apachectl configtest
Warning: DocumentRoot [/usr/local/apache/htdocs/www/domain222] does not exist
Syntax OK
[root@www bin]#

PINGing domain222 and its IP is good.  When browse the web all I get is the index.html page from /usr/local/apache/htdocs/www/domain111 as the default, what now?
sorry... kinda lost for a while.

>Also I am wonderring about
>
>                     Ahoffman's comment, what's  Allow from 10.1.35.200?

to allow proxy connection only from my pc (test environment).

From my understanding, I have a couple of servers and I tried this virtualnamehosting under 1 static IP.  I surf the web for the answer and apparantly it may seem like an apache problem.  It doesn't work.  If anyone has set this up please let me know how this is possible.  Thanks!

larry 718,

my initial posting is taken straight from my test box (with some modification on IP address to protect the innocent - me).  I might be able to resimulate.

I'm not sure how urgent you need this.  I would say give me a few days to dig my hd for RH installation. :)

I'll look it up.
well i don't work much with linux but i do with windows apache and i have mine set up as this
Note: i have had prob with this when i set any of these vhost #1 it seems like the first vhost is the default server i donno y but it does.

NameVirtualHost * <=== Any IP Address

# server 1 is main
<VirtualHost *>
    ServerAdmin Web@server1.com
    DocumentRoot c:/www/serv1/www
    ServerName www.server1.com
    ErrorLog c:/www/serv1/logs/error.log
    # Code Red Virus Attacks for Windows IIS 4.x - 5.x
    SetEnvIf Request_URI "^/default.ida(.*)$" code_red_attacks attacks
    SetEnvIf Request_URI "root\.exe(.*)$" nimda_attacks attacks
    SetEnvIf Request_URI "cmd\.exe(.*)$" nimda_attacks attacks
    CustomLog c:/www/serv1/logs/codered.log common env=code_red_attacks
    CustomLog c:/www/serv1/logs/nimda.log common env=nimda_attacks
    CustomLog c:/www/serv1/logs/access_log common env=!attacks
    AddType text/html .ida
    AddHandler server-parsed .ida
    # End of Virus Handeler
    ErrorDocument 404 /error/404.html
    ScriptAlias /cgi-bin/ "c:/www/serv1/cgi-bin/"
</VirtualHost>

# no need for Virus Attack redirects on the rest. it all goes to the 1st vhost (default)
<VirtualHost *>
    ServerAdmin web@server2.com
    DocumentRoot c:/www/serv2/www
    ServerName www.server2.com
    ErrorLog c:/www/serv2/logs/docerror_log
    CustomLog c:/www/serv2/logs/access_log common
    ErrorDocument 404 /error/404.html
    ScriptAlias /cgi-bin/ "c:/www/serv2/cgi-bin/"
</VirtualHost>

<VirtualHost *>
    ServerAdmin web@server2.com
    DocumentRoot c:/www/serv2/sub/pc1/www
    ServerName pc1.server2.com
    ErrorLog c:/www/serv2/sub/pc1/logs/error_log
    CustomLog c:/www/serv2/sub/pc1/logs/access_log common
    ErrorDocument 404 /error/404.html
    ScriptAlias /cgi-bin/ "c:/www/serv2/sub/pc1/cgi-bin/"
</VirtualHost>

# thats how mine is setup and it works fine even the error pages go where they should and so does the # cgi-bin  but to tell the server what can be done with the cgi-bins you gotta define them first like this

<Directory "c:/www/serv1/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

    <Directory "c:/www/serv2/cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

    <Directory "c:/www/serv2/sub/pc1//cgi-bin">
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
    </Directory>

# it allworks fine with windows 2000 but you will need to change the paths with Linux hope this helps some
larry718,

What you want (to recap);
-Main RH7.1 Linux Server running Apache = domain1.com, domain2.com

-Rh7.1 Linux Server running Apache = domain3.com, domain4.com
-Win98 running Personal WebServer = domain5.com domain6.com
-WinNT running IIS4 = domain7.com, domain8.com
-Win2k running Apache Web Server = domain9.com, domain10.com


I'm not sure whether this would be a repeat of the above solution.  Apology if it is, but let me simplify from scratch.

One possible solution would be,

1. Get all the domain www.domain<x>.com to point to the Rh7.1.
2. Configure VirtualHosting on Apache on Rh7.1 for each of the Sites (www.domain1.com .. www.domain10.com), makesure mod_proxy is loaded.

3. For those domain that are hosted on a different machine, create a separate VirtualHost for each website

NameVirtualHost *

<VirtualHost *>
#  Your default virtual host is configured here first
</VirtualHost>

<VirtualHost *>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:/Program Files/Apache Group/Apache/Websites/Whatever"
    ServerName www.domain1.com
    ErrorLog logs/www.domain1-error.log
    CustomLog logs/ww.domain1-access.log common

  <IfModule mod_proxy.c>
      ProxyRequests On

     <Directory proxy:*>
        Order deny,allow
        Deny from all
        Allow from all
    </Directory>

    #
    # Enable/disable the handling of HTTP/1.1 "Via:" headers.
    # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
    # Set to one of: Off | On | Full | Block
    #
#    ProxyVia On

    #
    # To enable the cache as well, edit and uncomment the following lines:
    # (no cacheing without CacheRoot)
    #
    CacheRoot "C:/Program Files/Apache Group/Apache/proxy"
    CacheSize 5
    CacheGcInterval 4
    CacheMaxExpire 24
    CacheLastModifiedFactor 0.1
    CacheDefaultExpire 1
#    NoCache a_domain.com another_domain.edu joes.garage_sale.com
   ProxyPass           /     http://yourinternal-ip-for-domain1.com/
   ProxyPassReverse      /     http://yourinternal-ip-for-domain1.com/

    </IfModule>

</VirtualHost>

Create as many VirtualHost as you need.

I hope this helps.

good luck

4. Restart Apache.
larry718,

What you want (to recap);
-Main RH7.1 Linux Server running Apache = domain1.com, domain2.com

-Rh7.1 Linux Server running Apache = domain3.com, domain4.com
-Win98 running Personal WebServer = domain5.com domain6.com
-WinNT running IIS4 = domain7.com, domain8.com
-Win2k running Apache Web Server = domain9.com, domain10.com


I'm not sure whether this would be a repeat of the above solution.  Apology if it is, but let me simplify from scratch.

One possible solution would be,

1. Get all the domain www.domain<x>.com to point to the Rh7.1.
2. Configure VirtualHosting on Apache on Rh7.1 for each of the Sites (www.domain1.com .. www.domain10.com), makesure mod_proxy is loaded.

3. For those domain that are hosted on a different machine, create a separate VirtualHost for each website

NameVirtualHost *

<VirtualHost *>
#  Your default virtual host is configured here first
</VirtualHost>

<VirtualHost *>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "C:/Program Files/Apache Group/Apache/Websites/Whatever"
    ServerName www.domain1.com
    ErrorLog logs/www.domain1-error.log
    CustomLog logs/ww.domain1-access.log common

  <IfModule mod_proxy.c>
      ProxyRequests On

     <Directory proxy:*>
        Order deny,allow
        Deny from all
        Allow from all
    </Directory>

    #
    # Enable/disable the handling of HTTP/1.1 "Via:" headers.
    # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
    # Set to one of: Off | On | Full | Block
    #
#    ProxyVia On

    #
    # To enable the cache as well, edit and uncomment the following lines:
    # (no cacheing without CacheRoot)
    #
    CacheRoot "C:/Program Files/Apache Group/Apache/proxy"
    CacheSize 5
    CacheGcInterval 4
    CacheMaxExpire 24
    CacheLastModifiedFactor 0.1
    CacheDefaultExpire 1
#    NoCache a_domain.com another_domain.edu joes.garage_sale.com
   ProxyPass           /     http://yourinternal-ip-for-domain1.com/
   ProxyPassReverse      /     http://yourinternal-ip-for-domain1.com/

    </IfModule>

</VirtualHost>

Create as many VirtualHost as you need.

I hope this helps.

good luck

4. Restart Apache.
Dear Samri,

Sorry to get back so late, had a job change.  I try this setting but it doesn't work.  

my current setting is:


<VirtualHost *>
ServerAdmin root@website1.com
DocumentRoot /www/www.website1.com
ServerName www.website1.com
ErrorLog logs/www.website1.com-error_log
CustomLog logs/www.website1-access_log common
</VirtualHost>

... and so on.

this works well, but not except for 1 machine.

and i must type exactly "www.website2.com" to get to website2.  If i type "website2.com" it defaults to website1.

any new insight into this problem, experts?
ASKER CERTIFIED SOLUTION
Avatar of samri
samri
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial