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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apache Virtual Hosts. 1

Status
Not open for further replies.

macii2

IS-IT--Management
Oct 29, 2006
2
US
Hello all,

Im getting ready to host three websites internally rather than continuing usage of the drab site creation tools provided by my Domain Name Provider. I have a couple of questions for you apache guru's.

I am under the impression that all I will have to do is change the the DNS for my current website(s) at Network solutions and point them to the static IP(provided by ISP) of the linux box I will be running the apache server on? Ofcourse having the apache server configured properly. I will be running the firewall service on the linux box so the linux maching will be connected straight to the static IP. No router in bettween. Is there anything else I need to do?

Thanks for your help.
 
If you have more than one machine that will be accessing the internet, you can use a router. What most people do is use the dhcp server from the router assign dynamic addresses to their win boxes and provide a static ip for the server. You router will have 2 ip addresses. The one given to you from your isp will be on the router's wan side. The lan side will have an address something like 192.168.1.1. You would give your server (linux box) an address something like 192.168.1.10. This assumes that this number is taken out of the pool of dynamic ip addresses used for dhcp. You can configure your router to set aside a block of addresses for static addresses. Then setup port forwarding of all http traffic to the ip if your server on port 80. It is very easy to setup apache to server multiple domains on one ip. You would use name based addressing. This means that apache will look for a directive called ServerName to match the name of the requested domain. Here is an example vhost container:

Code:
  <VirtualHost *:80>
    ServerAdmin webmaster@domain1.com
    DocumentRoot /var/[URL unfurl="true"]www/domain1/html[/URL]
    ServerName domain1.com
    ErrorLog /var/[URL unfurl="true"]www/domain1/logs/error_log[/URL]
    CustomLog /var/[URL unfurl="true"]www/domain1/logs/acess_log[/URL] common


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

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

    </Directory>

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

    <Directory "/var/[URL unfurl="true"]www/domain1/cgi-bin">[/URL]
       AllowOverride None
       Options None
       Order allow,deny
       Allow from all
    </Directory>

</VirtualHost>

Near the bottom of your httpd.conf file you will see a sample vhost container and this directive:
#NameVirtualHost *:80

Remove the '#' to uncomment the line. Now look for a line that looks like this:

include conf.d/*.conf

This tells apache to append every thing in that directory that ends in .conf to httpd.conf. Now you can create an empty file called vhosts.conf and cut and paste the sample I gave you above into that file. You can use a separater like ################# Domain1 ################# in between each vhost container. Then just edit each one replacing 'domain1' with the actual name. This example assumes you have your path structure is the same as the following:

/var//var//var/
As a rule, directories have their permissions set to 755 and files to 644. If your script needs to write to a file or directory, you will be asked to set it to 777. That should at least get you started. Don't forget to restart apache any time you change any of the .conf files. To do that from the command line you would type this command:

apachectl restart

In place of restart, you could also use start, stop or graceful. You would want to use graceful when you have visitors on any of your websites where a regular restart would just bump them off. Good luck. I hope I didn't get too confusing.
 
Thanks RhythmAce, Not to confusing at all. Thanks for the tip on setting a vhosts.conf file in the conf.d <dir>..that will make it alot easier to manage. And I guess I could set up a default(fallback) site for those running old browsers that dont send http header info. That would go in the main httpd.conf right? It has to be the first vhost? Anyhow thanks for your help.
 
No it can go in the vhosts.conf file. And yes you are correct. The first vhost defined becomes the default.


 
I am REALLY new to web hosting and I just came across your post, tried the config as explained and when I went to restart the server it came up and said that the operation failed... I installed apache in a package with xampp so that I could use Zpanel. the main problem I am having is that apache is pointing all domains to my main htdocs folder and I need it setup with vhosts. any idea why it's not restarting for me? If you need I can post my conf and vhosts script for reviewed... Any help would be greatly appreciated!! Thanks

my setup
xampp with apache 2.2, php 5.1, mysql 5
zpanel
microsoft windows server 2003 ent edition
 
You should problably start a new thread. In short, if apache can't distinguish your virtual host names, it will serve the first. If virtual hosts are not configured properly at all, it will use the main DocumentRoot. Also be sure to check this forum's FAQ's.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top