Ways to enable and deactivate a site
A2ensite Site name A2dissite Station Roll Call
Name-based virtual host (distinguished by domain name)
After installing Apache, there is a virtual host called default. When you create a new virtual host, you can directly copy the default virtual host's configuration file, and then modify the configuration parameters for the new virtual host.
#copy/etc/apache2/site-available/default/etc/apache2/site-available/sitename
Test environment
Operating system: Ubuntu Server 12.04 LTS
Test machine Address: 10.39.6.59
Test machine domain Name: *.example.com
Basic Configuration
We all know that if we want to set up multiple domain names or hostnames on a single machine, we need to use a name-based virtual host. So how do you set it up? This is the problem that this guide wants to solve. There is a Apache2 master profile apache2.conf in the Ubuntu/etc/apache2/directory. In this file we can see the following fields:
# Include The virtual host configurations:include/etc/apache2/sites-enabled/[^.#]* (none in version 12.04 [^.#]*)
This line means that the file contains all the files in the/etc/apache2/sites-enabled/directory that do not contain the "." or "#" characters. When we list the file of this directory, we find that there is only one 000-default soft link file, the actual connection is the default file in the/etc/apache2/sites-available directory, it is not difficult to see that the file name does not include "." or "#". So this file is, of course, to be included in the config file apache2.conf. Open the file and discover that it is actually a configuration file for a virtual host, but because the virtual host in the file is *, it is actually a generic configuration file. If we are going to build a virtual host, we need to change the file to look like this:
<virtualhost *:80>servername www.firehare.comServerAdmin admin@mail.firehare.comdocumentroot/var/www/< Directory/>options followsymlinksallowoverride none</directory><directory/var/www/>options Indexes FollowSymLinks multiviewsallowoverride Noneorder Allow,denyallow from all# This directive allows us to apache2 ' s DEFA Ult start page# in/apache2-default/, but still have/go to the right place# commented out for Ubuntu#redirectmatch ^/$/ apache2-default/</directory>scriptalias/cgi-bin//usr/lib/cgi-bin/<directory "/usr/lib/cgi-bin" > allowoverride noneoptions execcgi-multiviews +symlinksifownermatchorder allow,denyallow from all</Directory> errorlog/var/log/apache2/error.log# Possible values Include:debug, info, notice, warn, error, crit,# alert, Emerg. LogLevel warncustomlog/var/log/apache2/access.log combinedserversignature onalias/doc/"/usr/share/doc/" < Directory "/usr/share/doc/" >options Indexes multiviews FollowsymlinksallowoVerride Noneorder Deny,allowdeny from Allallow to 127.0.0.0/255.0.0.0::1/128</directory></virtualhost>
Let's take a look at the setup statements in the above setting that are related to the virtual host:
' namevirtualhost:80 ': what we're going to do is a name-based virtual host that listens on a port of 80.
' <virtualhost *:80> and </VirtualHost> ': Represents the configuration of a virtual host in it. Note If the above field specifies a port number, specify the
' ServerName www.firehare.com ': Set the domain name of the virtual host, www.firehare.com can be any domain name you register
' ServerAdmin admin@mail.firehare.com ': Set up mail for this virtual host administrator
' documentroot/var/www/': Sets the home directory path for this virtual host
' Errorlog/var/log/apache2/error.log ': Set error message for this virtual host
' Customlog/var/log/apache2/access.log combined ': Set access information for this virtual host
This allows us to configure a virtual host www.firehare.com. However, since this is the default configuration, after Apache2 restarts, any domain name that you enter into the DNS server that points to this host will be directed to the directory www.firehare.com this default configuration points to/var/www. Unless the domain name is used by other virtual host configuration, for example, we also configured the edunuke.firehare.com point to this machine, and configured the corresponding virtual host, so that the input domain name edunuke.firehare.com will be in the directory of the domain name.
Further clarification
To make it clear that we add a virtual host site example.com, first create a file Edunuke in the/etc/apache2/sites-available/directory and edit the file:
<virtualhost *:80>servername edunuke.example.comServerAdmin edunuke@mail.example.comdocumentroot "/var/www/ edunuke/"errorlog"/var/log/apache2/edunuke_errors.log "Customlog"/var/log/apache2/edunuke_accesses.log "common </VirtualHost>
The exact meaning of the setting is similar to the one above, which I will not say more. And then run the command:
sudo a2ensite Edunuke
In this case, the virtual host site edunuke.example.com is already installed. You can also find one more soft link to/etc/apache2/sites-available/edunuke in the/etc/apache2/sites-enabled/directory. The next step is to restart the Apache2 to run the virtual host site:
Sudo/etc/init.d/apache2 Restart Here can use reload reload
If you enter edunuke.example.com on the browser, you will be directed to the/var/www/edunuke directory, and the other domain names that point to this computer will refer to the/var/www directory in the default configuration. Familiar with Apache2 's friends will ask why such trouble, put in a file is not OK? Why use two of files? It's really simple, because if I'm going to maintain the Edunuke site, I just run the command:
sudo a2dissite edunukesudo/etc/init.d/apache2 restart
, so that you can maintain Edunuke this site, but also does not affect the normal operation of other sites.
Advanced Configuration
Here is a simple virtual host configuration method. This basically satisfies most of our needs. But if the installation of Zope+plone, the above setting is not enough, because the zope+plone structure of the port is not a 80 port, so we have to do port redirection. To be able to do this, we have to activate the Rewrite and Proxy two modules. The activation module is very simple, as with the site configuration directory, there are also two module configuration directories in Apache2: Mods-available and mods-enabled. In the Mods-available directory are all available modules, while in the mods-enabled directory are modules that have been installed in Apache2. Since the configuration boot files for the Rewrite and Proxy modules are already in the Mods-available directory, you simply need to install them into Apache2. Use the command:
sudo a2enmod rewritesudo a2enmod Proxy
Then, add the virtual host site plone.example.com, creating a file Plone similar to the Edunuke site creation in the/etc/apache2/sites-available/directory. Obviously there are no "." or "#" characters in this file name. Then edit the file:
<virtualhost plone.example.com:80>servername plone.example.comServerAdmin Plone@mail.example.comerrorlog "/ Var/log/apache2/plone_errors.log "Customlog"/var/log/apache2/plone_accesses.log "CommonRewriteEngine Onrewriterule ^/(. *) http://127.0.0.1:8081/virtualhostbase/http/plone.firehare.com:80/plone/virtualhostroot/$1 [L , P]<proxy *>order Deny,allowdeny from Allallow to all</proxy></virtualhost>
This installs the Plone.example.com Web hosting site, can be redirected to the Zope+plone site by entering http://plone.example.com in the address bar in the browser.