Solved

virtual host - 1 static ip

Posted on 2001-09-02
20
367 Views
Last Modified: 2013-11-18
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.
0
Comment
Question by:larry718
  • 8
  • 6
  • 2
  • +2
20 Comments
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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 ;-)
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
I am a newbie at apache.  ahoffmann, I've tried this but can't get it to work. Can you elaborate?
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
I am a newbie at apache.  ahoffmann, I've tried this but can't get it to work. Can you elaborate?
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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>
0
 
LVL 51

Expert Comment

by:ahoffmann
Comment Utility
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.
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
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.
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
Also I am wonderring about

Ahoffman's comment, what's  Allow from 10.1.35.200?
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
Also I am wonderring about

Ahoffman's comment, what's  Allow from 10.1.35.200?
0
 
LVL 16

Expert Comment

by:The--Captain
Comment Utility
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

0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:larry718
Comment Utility
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?
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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).

0
 
LVL 1

Author Comment

by:larry718
Comment Utility
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!

0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 

Expert Comment

by:Black-Lie
Comment Utility
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
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 
LVL 15

Expert Comment

by:samri
Comment Utility
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.
0
 
LVL 1

Author Comment

by:larry718
Comment Utility
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?
0
 
LVL 15

Accepted Solution

by:
samri earned 300 total points
Comment Utility
larry,

Yes, somehow the VirtualHost will (I presume, never really test this), do an exact match (not cases sensitive), by the Host header in request URL.  One option to take care of this is to add two VirtualHost, or for www.website2.com, and one for website2.com.  

give this suggestion a try.

Another option is;
According to Apache doc's, the first VirtualHost will be the default VirtualHost should there is not matching VirtualHost found.

Taking this into consideration, you can have a a rewriting rule to rewrite website2.com, to it's fullname www.website2.com.

Some details on Apache's mod_rewrite.
http://httpd.apache.org/docs/mod/mod_rewrite.html

Practical Rewriting guide.
http://httpd.apache.org/docs/misc/rewriteguide.html
Look for the section that talks about: Canonical Hostnames

This option would require you to add the following rewriting rule in the VirtualHost container for the default VirtualHost (the first VirtualHost defined).

RewriteEngine on
RewriteCond %{HTTP_HOST}  ^website2\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)        http://www.website2.com/$1 [L,R]


Personally I would go for the extra VirtualHost option, since it's much straightforward.  URL Rewriting will be a bit tricky, and slower (according to some opinion).
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
Microservice architecture adoption brings many advantages, but can add intricacy. Selecting the right orchestration tool is most important for business specific needs.
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
The viewer will learn how to count occurrences of each item in an array.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now