Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Virtual server setup help? 1

Status
Not open for further replies.

AccessXP

IS-IT--Management
Jan 29, 2002
132
Is there a website that gives step by step directions on how to do this? I have tried for a few days but no luck, I either get one web page or the other.

Any help please?

Thank you.
 
You came to the right place. First of all, if you use virtual hosting for one domain, you must use it for all of them because the one in the "main" section will no longer get served. If no match is found to the domain being requested, the first vhost defined will be the default not the one in the main section. Another thing you need to know before going through the steps is that you will be using name based addressing. With this type of addressing apache "Listens" for all addresses on port 80 (http) for a request. It matches the requested domain to the ServerName directive in each vhost. Each vhost has a directive called DocumentRoot which tells apache where to find this domain's pages. Finally, you should know that you can use almost any directive in the main section in your vhost container or your vhost's directory containers. Where a directive applies depends on where you put it. If you place it in the main section, it applies globally. If you place it in a directory container within a particular vhost, it will apply to that directory and its sub-directories. To start using name based addressing for you virtual hosts, you will need to set a few directives in the main section.

UseCanonicalNames Off

Listen 192.168.1.10:80 (use your machine's ip here)

NameVirtualHost *

The following is a sample vhost container. copy and paste it to the bottom of httpd.conf as many times as you need (one for each vhost).

Code:
<VirtualHost *>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/[URL unfurl="true"]www/mydir/html[/URL]
    ServerName mydomain.com
    ServerAlias [URL unfurl="true"]www.mydomain.com[/URL]
    ErrorLog /var/[URL unfurl="true"]www/mydir/logs/error_log[/URL]
    CustomLog /var/[URL unfurl="true"]www/mydir/logs/access_log[/URL] combined

      <Directory "/var/[URL unfurl="true"]www/mydir/html">[/URL]

          Options Indexes FollowSymLinks
          AllowOverride None
          Order allow,deny
          Allow from all

      </Directory>

   ScriptAlias /cgi-bin/ "/var/[URL unfurl="true"]www/mydir/cgi-bin/"[/URL]

      <Directory "/var/[URL unfurl="true"]www/mydir/cgi-bin">[/URL]

          AllowOverride None
          Options None
          Order allow,deny
          Allow from all

      </Directory>

      
</VirtualHost>

You should be ready to go. Don't forget to restart apache any time you make changes to httpd.conf.
 
I forgot to mention that the first three directives, UseCanonicalName, Listen and VirtualHostName, are already defined. You just need to edit or uncomment them.
 
RhythmAce,

Thank you for your help.
 
You are very welcome. Were you able to get it up and running yet?
 
Here is the error I got,


VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results

Any I deas?
 
This error may or may not actually be a problem. It's just saying that you have a particular unsuppored condition. Somewhere, you have a VirtualHost like:

<VirtualHost _default_:443>
#some other stuff
</VirtualHost>

So, if you set your new VirtulalHosts as RythmAce showed above you have:

<VirtualHost *>
#some other stuff
</VirtualHost>

The error is just telling you that _default_ is not the same as *. So to get rid of this error, just find <VirtualHost _default_:443> and change it to <VirtualHost *:443>. This directive could be in your httpd.conf file or one of the included files like commonhttpd.conf
 
You have an ssl vhost defined. I don't know what OS you are running but on most linux distros, you will find a file called /etc/httpd/conf.d/ssl.conf. Just rename this file to ssl.conf.bak or delete it if you don't plan on using ssl and everything should work fine. Don't forget to restart (start?) apache. Another tip is that the directory where you want your log files MUST exist or apache will refuse to start.



 
Thanks--

I will try this today and report back on the results.
 
Also, if you want to use an ssl host, you can mix name based and ipbased virtual hosts in your httpd.conf file. Namebased virtual hosts do not work with SSL servers because of the way the headers are received by the server.
You'll need to define a second ip on your server (you can use an alias), and make sure you add a listen directive for it. e.g.

Listen 192.168.0.2
Listen 192.168.0.3

Then your virtual servers would look something like this..

NameVirtualHost 192.168.0.2:80

<VirtualHost 192.168.0.2:80>
ServerName DocumentRoot /web/docs/mydomain
ErrorLog "/web/logs/errors"
TransferLog "/web/logs/access"
</VirtualHost>

#SSL Virtual Host

<VirtualHost 192.168.0.3:443>
ServerName SSLEngine on
SSLVerifyClient none
SSLVerifyDepth 10
SSLCertificateKeyFile /web/certs/privkey.pem
SSLCertificateFile /web/certs/cert.cer
DocumentRoot /web/docs/ssl
ErrorLog "/web/logs/errors"
TransferLog "/web/logs/access"
</VirtualHost>
 
Okay--

here is the deal I inserted the code as shown above and changed the domians accordingly and renamed the ssl.conf file.

Restarted Apache no error statments.

Now if you vist the site one domain is the Apache test page and the other is the the temp page I created but displays for the wrong domain name.

Any Ideas?
 
Can you post the part of httpd.conf that has you vhosts? You can change the domain names if providing them makes you uncomfortable. In the main section, did you comment out the ServerName directive or set it to localhost?

 
RhythmAce

Here is the code.

# Use name-based virtual hosting.
#
NameVirtualHost *

# Where do we put the lock and pif files?
LockFile "/var/lock/httpd.lock"
CoreDumpDirectory "/etc/httpd"

# Defaults for virtual hosts

# Logs


#
# Virtual hosts
#

# Virtual host _default_
<VirtualHost *>
DocumentRoot /var/
ServerAdmin webmaster@r3marketing.com
ServerName DirectoryIndex index.php index.html index.htm index.shtml

LogLevel debug
HostNameLookups off

</VirtualHost>

# Virtual host promotionaldimensions.com
<VirtualHost *>
DocumentRoot /var/
ServerAdmin webmaster@promotionaldimensions.com
ServerName
</VirtualHost>

Thanks.
 
RhythmAce,

I changed the code to look more like what you sent me and now I see test pages for both domians? Here is the code:


NameVirtualHost *

# Where do we put the lock and pif files?
LockFile "/var/lock/httpd.lock"
CoreDumpDirectory "/etc/httpd"

# Defaults for virtual hosts

# Logs


#
# Virtual hosts
#

# Virtual host _default_
<VirtualHost *>
ServerAdmin webmaster@r3marketing.com
DocumentRoot /var/ServerName r3marketing.com
ServerAlias ErrorLog /var/CustomLog /var/ combined

<Directory "/var/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

</Directory>

ScriptAlias /cgi-bin/ "/var/
<Directory "/var/
AllowOverride None
Options None
Order allow,deny
Allow from all

</Directory>
</VirtualHost>

<VirtualHost *>
ServerAdmin webmaster@promotionaldimensions.com
DocumentRoot /var/ServerName promotionaldimensions.com
ServerAlias ErrorLog /var/CustomLog /var/ combined

<Directory "/var/
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all

</Directory>

ScriptAlias /cgi-bin/ "/var/
<Directory "/var/
AllowOverride None
Options None
Order allow,deny
Allow from all

</Directory>

</VirtualHost>
 
Here are a couple things to check. Make sure that the directive UseCanonicalName is set to Off. Also Make sure that the ServerName in the main server section is Commented out. I also noticed that you have the DocumentRoots for both domains inside the main server's DocumentRoot (/var/ I'm not sure if this has anything to do with your problem, but it can get confusing. As a rule you would create or use a directory to hond all your domains. An example would be /var/ You would place your domain directories inside that i.e. /var/ Then you would create the html, cgi-bin and logs directories inside of that. The DocumentRoot would now be /var/ The reason I'm having you take your domains out of there is because any directives defined for the main server's directories, would apply to all their sub-directories which would include yours unless you redefine them.
 
Thanks I will try this and do some moving around. I will let you what happens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top