Code University

      "Where tuition is free!"

News | Images | Contact     
  • Home
  • Coding KC
  • Scripts
  • Software
  • Templates
  • Tutorials
  • About
 

Tutorials

Posted on Jun 30, 2010 at 20:35

Apache 2 - Virtual Hosts


Page Contents
[X] CLOSE

Local/External Sites

  • Setup local hosts
  • Setup external web sites
Toggle Page Contents
Setup local hosts
Edit hosts files > vi /etc/hosts ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 site1.com 127.0.0.1 site2.com 127.0.0.1 site3.com
Set loopback address to handle local urls of your choice. Here we are saying that site1.com, site2.com and site3.com will be the local urls used to access the three local test sites. This is handy for running sites locally for testing before deployment to a live server.

Edit apache2 vhosts configuration file > vi apache2/conf/extras/httpd-vhosts.conf # # Virtual Hosts # # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # Use name-based virtual hosting. # NameVirtualHost *:80 # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any block. # <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site1.com" ServerName site1.com ErrorLog "logs/site1.com-error_log" CustomLog "logs/site1.com-access_log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site2.com" ServerName site2.com ErrorLog "logs/site2.com-error_log" CustomLog "logs/site2.com-access_log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site3.com" ServerName site3.com ErrorLog "logs/site3.com-error_log" CustomLog "logs/site3.com-access_log" common </VirtualHost>
Edit the httpd-vhosts.conf file putting in a VirtualHost section for each site as shown. Document Root = full path to site on local server ServerName = url that will be typed in to access site ErrorLog = log to use for error messages CustomLog = log to use for server messages

Setup external web sites
Edit apache2 vhosts configuration file > vi apache2/conf/extras/httpd-vhosts.conf <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site1.com" ServerName www.site1.com ErrorLog "logs/site1.com-error_log" CustomLog "logs/site1.com-access_log" common </VirtualHost>> <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site2.com" ServerName www.site2.com ErrorLog "logs/site2.com-error_log" CustomLog "logs/site2.com-access_log" common </VirtualHost> <VirtualHost *:80> DocumentRoot "/usr/local/apache2/htdocs/site3.com" ServerName www.site3.com ErrorLog "logs/site3.com-error_log" CustomLog "logs/site3.com-access_log" common </VirtualHost>
All that is required in order to get a real set of virtual websites up and running is to edit the httpd-vhosts.conf file. The only difference here from setting up a local host is you need to put in the fully qualified url in the ServerName setting as shown.


Tagged: Linux, UNIX
Tutorials
  • Introduction
  • Documentation
    Creating man(ual) pages
  • Dual Boot Systems
    Fedora/Windows XP
    Red Hat/FreeBSD
  • Files
    Dynamic PDF generation
  • Linux
    NTP server setup
    Root password reset (grub)
  • Networking
    ndiswrapper setup (wireless)
  • Version Control
    CVS - repo setup
  • Web Hosting
    Apache 2 - Installations
    Apache 2 - Configurations
    Apache 2 - Virtual Hosts
Resources
  • CodeIgniter - MVC Framework
  • HowtoForge - Linux Tutorials
  • Linux Today - Linux News
  • Lxer - Linux News Feed
  • Monsterb - Linux, Podcasting
  • MySQL - Databasing
  • Perl - Programming
  • PHP - Programming
  • Systhread - Admin & Programming
  • W3Schools - Web Tutorials
About

Code University contains a wealth of technical information aimed at the computer sciences.


 
Home | Coding KC | Scripts | Software | Templates | Tutorials | About
Top ^
 
© 2007-2012 Code University| Disclaimer
Website template by Arcsin