Apache Virtual Host configuration [Ubuntu]

Source: Internet
Author: User
Tags plone
= = Basic Configuration = = We all know that if we want to set more than one domain name or hostname on a single machine, we need to use a virtual host based on the name. So how do you set it up? This is the HowTo to solve the problem. In the/etc/apache2/directory of Ubuntu, there is a Apache2 master configuration file apache2.conf. In this file we can see this line of content:
Code:
include/etc/apache2/sites-enabled/[^.#]*
This line means that the file contains all the files in the/etc/apache2/sites-enabled/directory that contain the characters "." or "#". When we list the files of the 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 easy to see that the file name does not contain "." 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 want to set up a virtual host, then we need to change the file to look like the following:
Code:
Namevirtualhost 10.39.6.59 <virtualhost 10.39.6.59>      ServerName www.firehare.com       ServerAdmin ubuntu.firehare@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 &nbsp ;        # in/apache2-default/, but still have/goTo the right place          # commented out for Ubuntu     & nbsp;    #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 &Nbsp;    serversignature on      alias/doc/"/usr/share/doc/"       <directory "/usr/share/doc/" >          Options Indexes MultiViews followsymlinks          allowoverride None           order Deny,allow          deny to all           Allow from 127.0.0.0/255.0.0.0:: 1/128      </ Directory> </VirtualHost>
Let's analyze the settings in this setting that relate to the virtual host: * Namevirtualhost 10.39.6.59: It means that we're going to do a name-based virtual host with an IP address of 10.39.6.59 * <virtualhost 10.39.6.59> and </virtualhost>: Represents the configuration of a virtual host * ServerName www.firehare.com: Setting the domain name of the virtual host * ServerAdmin Ubuntu.firehare@gmail.com: Set up mail for this virtual host administrator * documentroot/var/www/: Set the virtual host's home directory path * errorlog/var/log/apache2/ Error.log: Set this virtual host error message * Customlog/var/log/apache2/access.log combined: Set the access information for this virtual host so we configured a virtual host www.firehare.com. However, since this is the default configuration, after Apache2 reboot, any domain name that you enter into the DNS server that points to the host will be directed to the/var/www directory that the default configuration points to www.firehare.com. Unless the domain name is used by other virtual host configuration, for example, we also configured the edunuke.firehare.com point to the local machine, and configured the corresponding virtual host, so, the input domain name edunuke.firehare.com will be the directory of the domain name. = = further explanation = = To explain clearly we add a virtual host site edunuke.firehare.com, first to the/etc/apache2/sites-available/directory to create a file Edunuke. Of course, there are no "." or "#" characters in this file name. Then edit the file:
Code:
<virtualhost 10.39.6.59> ServerName edunuke.firehare.com ServerAdmin ubuntu.firehare@firehare.com Doc Umentroot "/var/www/edunuke/" ErrorLog "/var/log/apache2/edunuke_errors.log" Customlog "/var/log/apache2/edunuke" _accesses.log "Common </VirtualHost>
The specific meaning of the set is similar to the above, which I will not say more. Then run the command: {{{a2ensite Edunuke}}}} so the virtual host site edunuke.firehare.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:
Code:
Sudo/etc/init.d/apache2 restart
If you enter edunuke.firehare.com on the browser, you will be directed to the/var/www/edunuke directory, and any other domain name that points to this computer will be referred 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 also OK. Why do you use two files? It's really simple, because if I want to maintain the Edunuke site, I just run the command:
Code:
sudo a2dissite edunuke sudo/etc/init.d/apache2 restart
, this can maintain Edunuke this site, but also does not affect the normal operation of other sites. = = Advanced Configuration = = above discusses the simple virtual host configuration method. This basically meets most of our needs. However, if the installation of Zope+plone, the above setting is not enough, because the zope+plone structure of the port is not 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 simple, like the site configuration directory, and there are two module configuration directories in Apache2: Mods-available and mods-enabled. In the Mods-available directory are all available modules, and in the mods-enabled directory are the modules that have been installed into Apache2. Since the configuration boot file for the Rewrite and Proxy modules is already available in the Mods-available directory, simply install it into the Apache2. To use the command:
Code:
sudo a2enmod rewrite sudo a2enmod proxy
Then, add a virtual host site plone.firehare.com, similar to Edunuke site creation to create a file Plone in the/etc/apache2/sites-available/directory. Obviously, there is no "." or "#" in this file name of the two characters. Then edit the file:
code:
<virtualhost 10.39.6.59>       ServerName plone.firehare.com      ServerAdmin ubuntu.firehare@firehare.com      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.firehare.com:80/plone/virtualhostroot/$1 [L,P]       <proxy *>          order Deny,allow           Deny from all          Allow to all       </Proxy> </VirtualHost>

This will install the Plone.firehare.com virtual host site, you can enter the address bar in the browser http://plone.firehare.com can be redirected to the Zope+plone site

Http://hi.baidu.com/%C0%EE%B1%F8/blog/item/e825321297f71350f919b824.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.