This is in UbuntuCommunityThe Apache Virtual Host Configuration is found.
A basic configuration
We all know that if we want to set multiple domain names or host names on a single machine, we need to use a name-based virtual master
Machine. So how should we set it? This is the problem that this guide is trying to solve. In ubuntu/etc/apache2/Object
There is a master configuration file apache2.conf for apache2. In this file, we can see the following line of content:
Include/etc/apache2/sites-enabled/[^. #] *
This line indicates that the file contains the/etc/apache2/sites-enabled/directory file name does not contain "." or "#"
All files with two characters. When we list the files in 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, which is not difficult to see.
The part name does not contain "." or "#". Therefore, this file must be included in the configuration file apache2.conf. Dozen
Open this file and find that it is actually a configuration file of the virtual host. However, because the virtual host in this file is *,
Is a common configuration file. If we want to create a VM, we need to change the file to the following:
Namevirtualhost 10.39.6.59
[Virtualhost 10.39.6.59]
Servername www.britepic.org
Serveradmin Ubuntu@gmail.com "] Ubuntu@gmail.com
DocumentRoot/var/www/
[Directory/]
Options followsymlinks
AllowOverride none
[/Directory]
[Directory/var/www/]
Options indexes followsymlinks Multiviews
AllowOverride none
Order allow, deny
Allow from all
# This directive allows us to have apache2's default 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 none
Options execcgi-Multiviews + symlinksifownermatch
Order allow, deny
Allow from all
[/Directory]
Errorlog/var/log/apache2/error. Log
# Possible values include: Debug, info, notice, warn, error, crit,
# Alert, emerg.
Loglevel warn
Customlog/var/log/apache2/access. Log combined
Serversignature on
Alias/doc/"/usr/share/doc /"
[Directory "/usr/share/doc/"]
Options indexes Multiviews followsymlinks
AllowOverride none
Order deny, allow
Deny from all
Allow from 127.0.0.0/255.0.0.0: 1/128
[/Directory]
[/Virtualhost]
Next we will analyze the setting statements related to the VM in the above section:
'Namevirtualhost 10.39.6.59 ': indicates a name-based virtual host with its IP address
10.39.6.59
'[Virtualhost 10.39.6.59] and [/virtualhost]': indicates the configuration of a virtual host.
'Servername www.britepic.org ': sets the Domain Name of the VM.
'Serveradmin Ubuntu@gmail.com ': sets the mail for this VM Administrator
'Documentroot/var/www/': sets the main directory path of the VM.
'Errorlog/var/log/apache2/error. log': sets error information for this VM.
'Customlog/var/log/apache2/access. Log combined': sets the access information of the VM.
In this way, we have configured a virtual host www.britepic.org. However, this is the default configuration, so restart apache2.
Then, no matter you enter any domain name in the DNS server pointing to this host, it will be directed
The/var/WWW directory to which the default configuration points. Unless this domain name is used by other VM configurations, for example, we also configure
Edunuke.britepic.org points to the local machine and the corresponding virtual host is configured. In this way, enter the Domain Name
Edunuke.britepic.org will be placed in the directory of the expected domain name.
B further description
To make it clear, add another virtual host site edunuke.britepic.org. First, go
Create an edunuke file in the/etc/apache2/sites-available/directory. Of course, this file name does not contain "."
Or. Then edit the file:
[Virtualhost 10.39.6.59]
Servername edunuke.briepic.org
Serveradmin Ubuntu@britepic.org
DocumentRoot "/var/www/edunuke /"
Errorlog "/var/log/apache2/edunuke_errors.log"
Customlog "/var/log/apache2/edunuke_accesses.log" common
[/Virtualhost]
The specific meanings of the settings are similar to those above. Then run the following command:
Sudo a2ensite edunuke
In this case, the virtual host site edunuke.britepic.org has been installed. You can also
The/etc/apache2/sites-enabled/directory contains one more directory to/etc/apache2/sites-available/edunuke.
. Next, restart apache2 to run the VM site:
Sudo/etc/init. d/apache2 restart
In this way, if you enter edunuke.britepic.org in the browser, it will be directed to the/var/www/edunuke directory, and
If you enter another domain name pointing to the local machine, it will be indicated in the/var/WWW directory in the default configuration. A friend familiar with apache2 will ask
Why is it so troublesome to put it in a file? Why should I use two files? It is actually very simple, because if
To maintain the edunuke site, run the following command:
Sudo a2dissite edunuke
Sudo/etc/init. d/apache2 restart
You can maintain the edunuke site without affecting the normal operation of other sites.
C Advanced Configuration
I talked about the simple virtual host configuration method. This basically satisfies most of our needs. But if you want to install
In Zope + plone, the above settings are far from enough, because the port used by the Zope + plone structure is not 80
Port, so we have to do port redirection. To do this, we have to activate the rewrite and proxy modules.
The activation module is very simple. Like the site configuration directory, there are also two modules in apache2: mod-available
And mod-enabled. All available modules are in the directory of the "mod-available" and in the directory of the "mod-enabled" directory.
Is Installed in The apache2 module. Because rewrite and
The Configuration Guide file of the proxy module, so you just need to install it in apache2. Run the following command:
Sudo a2enmod rewrite
Sudo a2enmod proxy
Then, add the VM site plone.britepic.org, which is similar to the creation of the edunuke site.
Create a file plone in the/etc/apache2/sites-available/directory. Obviously, this file name does not contain "."
Or. Then edit the file:
[Virtualhost 10.39.6.59]
Servername plone.britepic.org
Serveradmin Ubuntu@britepic.org
Errorlog "/var/log/apache2/plone_errors.log"
Customlog "/var/log/apache2/plone_accesses.log" common
Rewriteengine on
Rewriterule ^ /(.*)
Http: // 127.0.0.1: 8081/virtualhostbase/HTTP/plone.britepic.org: 80/plone/virtualhostroot
/$1 [L, P]
[Proxy *]
Order deny, allow
Deny from all
Allow from all
[/Proxy]
[/Virtualhost]
In this way, the plone.briepic.org virtual host site has been installed. You can enter
the http://plone.britepic.org can redirect to the Zope + plone site.