Linux Apache bind multi-domain

Source: Internet
Author: User
Tags web hosting plone

1 on-line to find resources do not match

The Apache bound domain name found on the internet said to modify the http.conf file, but the Apache on my server is installed by Apt-get install, the installation method should be correct, but through find/-name "http.conf"- The result of the print search is empty, and the search using Find/-name "http.conf"-print is also empty, It may not be that all Apache-installed servers have http.conf files on them, at least not for me, but the server is running well.

If you are lucky enough to be able to find http.conf or httpd.conf files, then follow the online method settings. Here is a piece of blog I found, turn from: http://www.server110.com/apache/201310/1986.html, the specific content is as follows:

How does Apache bind multiple domain names
Open http.conf
1, servername 127.0 . 0.1   modified to  servername 72.167 . 11.30  
2,  #NameVirtualHost *     modified to   namevirtualhost 72.167 . 11.30 &NBSP,
3, has a virtual host format on the last side of the file,

#<virtualhost *>#   ServerAdmin [email][email protected][/email]#   /www/httpd/html/ server110.com#   ServerName server110.com#   errorlog logs/server110.com-error_log#   customlog logs/ server110.com-access_log common#</VirtualHost>


Simple to add:

72.167. 11.30> documentroot usr/local/www/ ServerName   72.167.  11.3072.167. 11.30> documentroot usr/local/www/server110.com/ ServerName   server110.com 72.167. 11.30> documentroot   usr/local/www/ntt.  CC/ ServerName   NTT. cc</VirtualHost>

Log files can also be added according to their own path.

Apache how to add a level two domain name
In httpd.conf, you need to open the Mod_rewrite feature (for a specific description of URL redirection, you can refer to the. htaccess usage Summary), specifically, at the end of httpd.conf, add the following:

int : Tolowerrewritemap vhost txt:/usr/local/etc/apache/vhost.maprewritecond ${lowercase:%{server_ NAME}} ^ (. +) $RewriteCond ${vhost:%1} ^ (/.*^/(. *) $%1/$1

The/usr/local/etc/apache is the path to your Apache server configuration file, which is changed according to the actual situation (for example, under/etc/httpd/). Then, create a file in the directory where the path is located: Vhost.map, the content is:

www.server110.com/usr/local/www/Server110.comwww.ntt. cc /usr/local/www/ntt. cc  /usr/local/www/server110.com/blog

Finally, in the site root directory/usr/local/www/, create the corresponding directory on it. If you need to add, modify, or delete domain names, subdomains, you just need to change the Vhost.map file without restarting the Apache process.

2 If you don't handle it,

However, I do not have this file on the server, how should I set it?

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:

/etc/apache2/sites-enabled/[^.#]* (No. 04 Version [^.#]*)

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 *: the>ServerName www.firehare.comServerAdmin [email protected]documentroot/var/www/<directory/>Options followsymlinksallowoverride None</Directory><Directory/var/www/>Options Indexes followsymlinks multiviewsallowoverride noneorder allow,denyallow from all# the directive allows us to Have apache2's default start Page#inch/apache2-default/, but still has/Go to the right place# commented out forUbuntu#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 Allallow127.0.0.0/255.0.0.0::1/ -</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 [email protected] ': 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 *:> "/var/www/edunuke/""  /var/log/apache2/edunuke_errors.log""/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  // can be reloaded here using 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 Edunuke sudo /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 rewrite sudo 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:>"/var/log/apache2/plone_errors.log "  "/var/log/apache2/plone_accesses.log"^/(. *) http:// 127.0.0.1:8081/virtualhostbase/http/plone.firehare.com:80/plone/virtualhostroot/$1 [L,P]<Proxy * >Order deny,allowdeny from Allallowto 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.

Port-based virtual host
<virtualhost *> documentroot/var/www/work/phabricator/webroot rewriteengine on RewriteRule ^/rsrc/(. *)-[L,QSA] Rewriterule ^/favicon.ico-[L,QSA] Rewriterule ^ (. *) $/index.php?__path__=$1 [B,L,QSA] </VirtualHost>

Linux Apache bind multi-domain

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.