How to build multiple sites using Apache

Source: Internet
Author: User
Tags require

There are about three common methods.

First: different ports of a single IP address

Type 2: multiple IP addresses and the same port (virtual space of independent IP addresses)

Third: bind the domain name to the root directory (virtual space with shared IP addresses)


The core configuration file name of Apache is "httpd. conf". The path is stored in the conf folder under the Apache Directory. To modify it, you only need to use notepad (it is recommended that you use another editor with the number of lines for easy modification). To make it take effect, you only need to save httpd. conf and restart apache.

Modify httpd. conf 187th ~ Line 3 (different httpd. conf may be different), that is, in ServerAdmin and ServerName, most of which are comments. Below are the main changes.

Note: If it is a server, back up httpd. conf and modify the file.

The code is as follows: Copy code

# 'Main' server configuration
#
# The directives in this section set up the values used by the 'main'
# Server, which responds to any requests that aren't handled by
# <VirtualHost> definition. These values also provide defaults
# Any <VirtualHost> containers you may define later in the file.
#
# All of these directives may appear inside <VirtualHost> containers,
# In which case these default settings will be overridden for
# Virtual host being defined.
#

#
# ServerAdmin: Your address, where problems with the server shocould be
# E-mailed. This address appears on some server-generated pages, such
# As error documents. e.g. Admin@your-domain.com
#
ServerAdmin admin@example.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# It explicitly to prevent problems during startup.
#
# If your host doesn' t have a registered DNS name, enter its IP address here.
#
ServerName www.example.com: 80

#
# Deny access to the entirety of your server's filesystem. You must
# Explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory/>
AllowOverride All
Require all denied
</Directory>

#
# Note that from this point forward you must specifically allow
# Particle features to be enabled-so if something's not working
# You might reset CT, make sure that you have specifically enabled it
# Below.
#

#
# DocumentRoot: The directory out of which you will serve your
# Events. By default, all requests are taken from this directory,
# Symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "g:/www"
<Directory "g:/www">
    #
# Possible values for the Options directive are "None", "All ",
# Or any combination:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
# Note that "MultiViews" must be named * explicitly * --- "Options All"
# Doesn' t give it to you.
    #
# The Options directive is both complicated and important. Please see
# Http://httpd.apache.org/docs/2.4/mod/core.html#options
# For more information.
    #
Options Indexes FollowSymLinks

    #
# AllowOverride controls what directives may be placed in. htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
    #
AllowOverride All

    #
# Controls who can get stuff from this server.
    #
Require all granted
</Directory>

The first type is generally the Test environment. After all, the port is added, and how to bind a domain name is also required after the domain name is accessed.

The example uses 80 and 8080 to access different root directories.

There is a Listen 80 in more than 50 rows. Add port 8080 below.

The code is as follows: Copy code

Listen 80
Listen 8080 <VirtualHost *: 80>
ServerAdmin admin@myxzy.com
ServerName localhost: 80
DocumentRoot "g:/www1"
<Directory "g:/www1">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *: 8080>
ServerAdmin admin@myxzy.com
ServerName localhost: 8080
DocumentRoot "g:/www2"
<Directory "g:/www2">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

The second type is multiple IP addresses with the same port.

IP Address 1: 192.168.2.2

IP address 2: 192.168.1.68

The same port is port 80.

The code is as follows: Copy code

<VirtualHost 192.168.1.68: 80>
ServerAdmin admin@myxzy.com
ServerName localhost: 80
DocumentRoot "g:/www1"
<Directory "g:/www1">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.2: 80>
ServerAdmin admin@myxzy.com
ServerName localhost: 80
DocumentRoot "g:/www2"
<Directory "g:/www2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

The third type is different from the IP address domain name and root directory (if the domain name is used, modify the local host for demonstration ).

The code is as follows: Copy code


<VirtualHost 192.168.2.2: 80>
ServerAdmin admin@myxzy.com
ServerName www.111cn.net
DocumentRoot "g:/www1"
<Directory "g:/www1">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.2.2: 80>
ServerAdmin admin@myxzy.com
ServerName www.111cn.net
DocumentRoot "g:/www2"
<Directory "g:/www2">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

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.