how to setup vhosts in apache - Printable Version +- Linux-Noob Forums (https://www.linux-noob.com/forums) +-- Forum: Linux Server Administration (https://www.linux-noob.com/forums/forum-8.html) +--- Forum: LAMP (https://www.linux-noob.com/forums/forum-83.html) +--- Thread: how to setup vhosts in apache (/thread-3455.html) |
how to setup vhosts in apache - anyweb - 2004-04-20 after a lot of trial and error and valuable help on IRC I finally got vhosts to work in apache ! first of all, I am assuming you have compiled apache as per this apache how-to secondly, the examples below are for a system that is based behind a NAT so local IP addresses (LAN) are used rather than domain names throughout, so if your apache server is NOT behind a NAT, then obviously replace the 100.0.0.3 IP address with your domain names or if you want, the WAN ip address. ok... let's say that for this example, that your server name is www.linux-noob.com and you want to have a vhosts called anyweb.kicks-ass.net and anyweb.homedns.org (heh, yup these are vhosts i have setup, and this is a WORKING example). I am also assuming that you have already setup the DNS for the domains above to point to the WAN ip of your apache server, if your apache server is behind a NAT then it will have a LOCAL ip address like 192.168.0.3 or something, if not, it will have the WAN ip address. In my case, my apache server is behind a NAT and gets a local IP from the firewall, the local ip for my apache server is 100.0.0.3 (you'll need to know that later). so, lets open our apache conf file, scroll right down to the end of the file to section 3 shown below. Code: vi /usr/local/apache/conf/httpd.conf Quote:### Section 3: Virtual Hosts# ok, now lets add the VHOST sections, please note, that once you add a VHOST, even just one, and if your servername is www.linux-noob.com then after you have added the VHOST, apache will default to the VHOST server name, this is important to note and because of this you must also add your 'current' servername as the 'first' VHOST. Code: NameVirtualHost 100.0.0.3:80 Ok in the above CODE, I have 3 VHOSTS listed, the first is my 'real' servername www.linux-noob.com, the second and third, are my actual 'virtual domain names'. If we take the third example, anyweb.homedns.org and examine the lines, we see that the first line is Code: <VirtualHost 100.0.0.3:80> . That tells apache that we have a virtual host on the following ip address 100.0.0.3 and it's on port 80. Lines with # infront are commented out and ignored. The next line that interests us is this one Code: DocumentRoot /usr/local/apache/websites/homedns/ This line tells apache that the virtual host called anyweb.homedns.org is situated locally in the directory /usr/local/apache/websites/homedns/. Now, we have to tell apache what this virtual server 'domain name' is actually called, Code: ServerName anyweb.homedns.org the line above, tells apache to look for any requests to anyweb.homedns.org and point them to the DocumentRoot we specified above that. That's it, pretty much done, now just close the section with this Code: </VirtualHost> so that your new VHOST section now reads something like Code: <VirtualHost 100.0.0.3:80> That in itself should work provided that you do indeed have a domain name called anyweb.homedns.org pointing to your WAN (internet) ip address (not the local IP address) and that you have created a directory locally called /usr/local/apache/websites/homedns/ and that you have chmod 755 that directory and chmod 644 any files in that directory. If it doesn't work make sure that your BindAddress sedtion in httpd.conf is correctly pointing to your LOCAL ip (or WAN ip if no NAT involved) such as in my example Code: BindAddress 100.0.0.3 ok to finish off and test your VHOST you should copy/paste your REAL server name details above the virtual host code above and make a minor change so that it looks like this: Code: NameVirtualHost 100.0.0.3:80 In the Code above, I have listed www.linux-noob as the FIRST vhost (and it is the 'default' website). If you do not list your default website in the VHOSTS section then all requests to it will fail. Also note that the line Code: NameVirtualHost 100.0.0.3:80 appears above the FIRST VHOST. This instructs apache to understand that it's using named virtual hosts, and they can be IP address (local or WAN) or DOMAIN NAMES (www.linux-noob.com). Whatever you have in NameVirtualHost must correspond with what you have after the VirtualHost statement, in my case above, it is 100.0.0.3:80. Also to note, in the first VHOST i have listed (the default website/linux-noob.com) i use the following line Code: ServerAlias www.linux-noob.com which instructs apache to give the server alias = what you specify. This is only required ONCE in the VHOST and it should generally be the 'default' website that you are hosting. ok, still with me ? if so, now you want to test that it all worked, save your httpd.conf file and stop and then restart apache by doing as follows: Code: [root@www root]# /usr/local/apache/bin/apachectl stop That's it, now test your VHOSTS ! here's three i've done already ;-) [/url]https://www.linux-noob.com http://anyweb.kicks-ass.net [url=http://anyweb.homedns.org]http://anyweb.homedns.org cheers anyweb how to setup vhosts in apache - morbondu - 2005-02-17 Don't forgot about your virtual host's access log files! Its a good idea to keep all of your virtual host logs seperated. This can easily be done by adding "CustomLog /path/filename" to your Vhost entry. In my Fedora Core 3 setup, my apache log files are located /var/log/httpd/. I'll use that path for the example below. Code: NameVirtualHost 100.0.0.3:80 I *think* the default httpd.conf setup will allow the CustomLog syntax to work. Hope this helps... how to setup vhosts in apache - tomdkat - 2005-02-18 Virtual hosting with Apache is neat. :) I admin a box that hosts 25-30 sites and keeping the logs stored on a per-host basis works out very well, especially when providing web log analysis on a per site basis. "Mass Virutal Hosting" is also neat, if you need to host sites without any special requirements. With "Mass Virtual Hosting", you can define sites by uploading the site to the server in a particular spot, registering the domain, and setting up the IP address assignment. No Apache restart required! :) This is a great thread. :) Peace... how to setup vhosts in apache - xDamox - 2005-02-18 Nice post anyweb, I also noticed you did not mention SELinux :)this make security even more secure. it can clamp down on people trying to abuse your CGI scripts and inject system commands in. if a user did successfully inject a command they would only be able to see the web dir and not browse directorys like /etc/. Have a look at SELinux with apache |