Red Hat 6&red hat 7 Apache website build (ii) virtual hosting

Source: Internet
Author: User
Tags hosting web hosting web hosting services

A virtual web host refers to running multiple Web sites on the same server, each of which does not actually

It is called a ' virtual ' Web host because it occupies the entire server independently. Using virtual web hosting services to take full advantage of services

The hardware resources of the device, which greatly reduces the cost of building and running the website.

With httpd, you can easily build a virtual host server and only run one httpd service to support

A large number of Web sites. The HTTPD supported virtual host types include the following three kinds.

Domain-based: A different domain name is used for each virtual host, but the corresponding IP address is the same. For example

The addresses of www.benet.com and WWW.ACCP com sites are 173.17 17.11. This is the most

The virtual Web host type.

Based on IP address: Different domain names are used for each virtual host, and the corresponding P-addresses are not the same. Such parties

Requires multiple network interfaces for the server, so the application is not very extensive.

Port-based: This approach does not use domain names, IP addresses to differentiate between different site content, but instead uses a different

TCP port number, so users need to specify a port number to access when browsing different virtual sites.

In the above several virtual web hosts, domain-based virtual host is the most widely used. is also the focus of this section

Content, about the other two types of virtual hosts, will only describe their configuration essentials. In addition, different types of virtual hosts are built

Sub-mechanisms are different, it is recommended not to use at the same time, so as not to confuse each other.

Experimental environment: A Red Hat 7 host or Red Hat 6 system, has been set up Apache website, yum Warehouse

One

1. We first configure the DNS server to resolve the domain name. (There is no source package installed, do not do too much introduction, the next blog to write DNS server, using Yum to install)

[email protected] ~]# Yum install-y bind bind-utils

2. Modify the global configuration file

[Email protected] ~]# vim/etc/named.conf

Options {

Listen-on Port: (any;};

allow-query {any;};

}

3. Modify the zone configuration file

[Email protected] ~]# Vim/etc/named.rfc1912.zones

Add the following content

Zone "Benet.com" in {

Type master;

File "Benet.com.zone";

allow-update {none;};

};


Zone "Accp.com" in {

Type master;

File "Accp.com.zone";

allow-update {none;};

};

4. Modify the Zone data configuration file

[Email protected] ~]# cd/var/named/

[Email protected] named]# cp-p named.localhost benet.com.zone

$TTL 1D

@ in SOA @ rname.invalid. (

0; Serial

1D; Refresh

1H; Retry

1W; Expire

3H); Minimum

NS @

A 127.0.0.1

AAAA:: 1

PTR localhost.

www in A 192.168.100.70

~

5. Copy the Benet configuration file to ACCP

[Email protected] named]# cp-p benet.com.zone accp.com.zone

6. Write the address of the machine into the library file

[Email protected] named]# echo "Namedserver 192.168.100.70" >/etc/resolv.conf

7. Start the DNS service

[[Email protected] named]# service named start

Two

1. Prepare the virtual machine documentation

[Email protected] ~]# mkdir-p/var/www/html/benet

[Email protected] ~]# mkdir-p/VAR/WWW/HTML/ACCP

2. Write a webpage to import into the directory

echo "

echo "

3. Create a directory to write the configuration file for the virtual machine

[Email protected] ~]# MKDIR/USR/LOCAL/APACHE/CONF.D

4. Create a virtual host document in the directory, a virtual path to the document

[Email protected] conf.d]# vim vdir.conf

alias/test/"/var/www/html/benet"

<directory "/opt/benet" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>


alias/test1/"/OPT/ACCP"

<directory "/VAR/WWW/HTML/ACCP" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>

The Order configuration item can be set to "Allow.deny" or "Deny,allow
To determine the host app "Allow" and "Deny"
The sequencing of the strategy.
Allow.deny: First "Allow" after "Deny", the default deny all the client address not explicitly allowed,
Deny,allow: After first "reject"
Allowed, all client addresses that are not explicitly denied are allowed by default.

(Please refer to the previous post for no explanation above)

[Email protected] conf.d]# vim vhost.conf

(Domain-based virtual host, you need to add hosts to the native or Linux point)

Windows is as follows

C:\WINDOWS\SYSTEM32\DRIVERS\ETC (default path)

192.168.100.70 www.accp.com

192.168.100.70 www.benet.com

<virtualhost 192.168.100.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/accp

ServerName www.accp.com

Errorlog Logs/bjxh.com-error_log

Customlog Logs/bjxh.com-access_log Common

</VirtualHost>

<directory "/VAR/WWW/HTML/ACCP" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>


<virtualhost 192.168.100.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/benet

ServerName www.benet.com

Errorlog Logs/bjxh.com-error_log

Customlog Logs/bjxh.com-access_log Common

</VirtualHost>

<directory "/opt/benet/" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>

<virtualhost 192.168.100.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/accp

ServerName www.accp.com

Errorlog Logs/bjxh.com-error_log

Customlog Logs/bjxh.com-access_log Common

</VirtualHost>

Listening Address: Use the Namevirtualhost configuration item to specify the IP address that provides the virtual host service, which is the domain

The IP address of each virtual Web host, such as 173.17.17.11, when queried.

Virtual host area: Use <virtualhost Listener address >....</virtualhost> zone configuration for each virtual

The WEB host establishes separate configuration content. This should include at least the Web site name of the virtual host, the Web root directory

Other configuration items, such as managing mailboxes, access logs, and so on, can be added according to actual needs.

Directory permissions, using the <directory directory location .... Dpcdo> zone configuration for each virtual Web

The host's Site directory sets access permissions, such as allowing anyone access. Directory access can inherit authorization from its parent directory

License, you can simplify the configuration by taking a method that directly authorizes access to the parent folder.

5. Configuring a port-based virtual host

Listen 8080


<virtualhost 192.168.100.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/benet

ServerName www.benet.com

Errorlog Logs/benet.com-error_log

Customlog Logs/benet.com-access_log Common

</VirtualHost>

<directory "/var/www/html/benet" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>


<virtualhost 192.168.100.70:8080>

ServerAdmin [email protected]

Documentroot/var/www/html/accp

ServerName www.accp.com

Errorlog Logs/accp.com-error_log

Customlog Logs/accp.com-access_log Common

</VirtualHost>

<directory "/VAR/WWW/HTML/ACCP" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>

6. Configure IP address-based host (need to add a network card to configure IP address and other information, and enable)

Need to add hosts on native or Linux to point

Windows is as follows

C:\WINDOWS\SYSTEM32\DRIVERS\ETC (default path)

192.168.100.70 www.accp.com

192.168.90.70 www.benet.com

<virtualhost 192.168.100.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/accp

ServerName www.accp.com

Errorlog Logs/accp.com-error_log

Customlog Logs/accp.com-access_log Common

</VirtualHost>

<directory "/VAR/WWW/HTML/ACCP" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>


<virtualhost 192.168.90.70:80>

ServerAdmin [email protected]

Documentroot/var/www/html/benet

ServerName www.benet.com

Errorlog Logs/benet.com-error_log

Customlog Logs/benet.com-access_log Common

</VirtualHost>

<directory "/var/www/html/benet" >

Options Indexes multiviews FollowSymLinks

AllowOverride None

Order Allow,deny

Allow from all

Require all granted

</Directory>

Three

    1. Add the path to the virtual host in the httpd configuration after the modification is complete

[Email protected] ~]# vim/usr/local/apache/conf/httpd.conf

Include conf.d/*.conf

2. Modify the httpd configuration file to the Web page path permission

<directory "/var/www/html/" >

AllowOverride None

Options None

Require all granted

</Directory>

3. After restarting the service, you can access the

[Email protected] ~]# service httpd restart

Note: This article notes the details

This article may make everyone wait too long (these days is too busy), small part here to apologize to you!


This article is from the "13219718" blog, please be sure to keep this source http://13229718.blog.51cto.com/13219718/1959687

Red Hat 6&red hat 7 Apache website build (ii) virtual hosting

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.