Apache Server--a virtual web host based on different domain names on different ports

Source: Internet
Author: User

About Apache:

Apache HTTP Server is an outstanding representative of open source software projects, providing web browsing services based on standard HTTP network protocols and maintaining over half of the Web service area over the long term. Apache servers can be run on Linux, Unix, Windows and many other operating system platforms.

The main features of Apache:

1. Open source code;
2. Cross-platform application;
3. Support various WEB programming languages;
4. Modular design;
5. Very stable operation;
6. Good safety.

Virtual Web Host:

A virtual web host is one that runs multiple Web sites on the same server, and each of these sites does not actually occupy the entire server on its own. In the actual enterprise application, can make full use of the server hardware resources, thus greatly reduces the website construction and the running cost.

The use of httpd can be very convenient to build a virtual host server, only need to run a httpd service can support a large number of Web sites at the same time. The HTTPD supported virtual host types include the following three kinds:
1. Domain-based: Use a different domain name for each virtual host, but the corresponding IP address is the same.
2. Based on IP address: each virtual host uses a different domain name, and the corresponding IP address is not the same.
3. Port-based: This approach does not use domain names, IP addresses to differentiate between different site content, but instead uses different TCP port numbers, so users are required to specify a port number to access when browsing different virtual sites.

This time we build an Apache server on the CentOS7 and configure a different domain-based and port-based Web site on this server.

Lab Environment:

CentOS 7 (Build httpd website service, DNS domain name resolution Service)
IP Address: 192.168.100.200
Mount the mirrored disc to the directory/mnt:mount/dev/cdrom/mnt

Start experiment: one: Test Apache services

Build httpd Service:

rpm -ivh /mnt/Packages/httpd-2.4.6-67.el7.centos.x86_64.rpm

To edit the httpd.conf configuration file:

vim /etc/httpd/httpd.confListen 192.168.100.200:80#Listen 80ServerName www.wzn.com:80
Test:

Turn off the firewall, turn on the service, and try to access:

systemctl stop firewalldsetenforce 0systemctl start httpd

The configuration file for a virtual Web host of multiple domain names and ports is in the regional configuration item under the installation directory, and its main form is as follows:
<directory/>//Defining the start of the "/" Directory area
Options followsymlinks//control options, allow use of symbolic links
AllowOverride None//Do not allow overlay configuration in the implicit control file
Order Deny,allow//application sequence of access control policies
Deny from all//prohibit anyone from accessing this area
</Directory>//Define the end of the "/" Directory area

Second: Virtual host based on different domain name

To create a configuration file with different domain name access:

[[email protected] ~]# cd /etc/httpd/conf.d/[[email protected] conf.d]# vim vhost.conf <Directory /var/www/html>           //设置目录访问权限     Order allow,deny           Allow from all           </Directory>     NameVirtualHost 192.168.100.200:80  //设置虚拟主机监听地址<VirtualHost 192.168.100.200:80>    //设置wzn虚拟站点区域    ServerAdmin [email protected]        //管理员邮箱    DocumentRoot /var/www/html/wzn/   //虚拟主机目录    ServerName www.wzn.com           //域名    ErrorLog logs/wzn.com-error_log  //错误日志>         CustomLog logs/wzn.com-access_log common //访问日志</VirtualHost>NameVirtualHost 192.168.100.200:80<VirtualHost 192.168.100.200:80>    ServerAdmin [email protected]    DocumentRoot /var/www/html/wzn01/    ServerName www.wzn01.com    ErrorLog logs/wzn01.com-error_log    CustomLog logs/wzn01.com-access_log common</VirtualHost>

To prepare a Web page document for a virtual host:

[[email protected] ~]# mkdir /var/www/html/wzn[[email protected] ~]# mkdir /var/www/html/wzn01[[email protected] ~]# echo "

We need to use the Domain name resolution service, install bind for domain name resolution:

To edit the Bind master configuration file:

[[email protected] conf.d]# vim /etc/named.confoptions { listen-on port 53 { 192.168.100.200; }; //监听本机地址 listen-on-v6 port 53 { ::1; }; directory "/var/named"; dump-file "/var/named/data/cache_dump.db"; statistics-file "/var/named/data/named_stats.txt"; memstatistics-file "/var/named/data/named_mem_stats.txt"; allow-query { any; }; //允许任意地址解析

Edit the Zone profile to place the domain name you need to resolve into the zone:

[[email protected] ~]# vim /etc/named.rfc1912.zones ##省略部分信息##zone "wzn.com" IN { type master; file "wzn.com.zone"; allow-update { none; };};zone "wzn01.com" IN { type master; file "wzn01.com.zone"; allow-update { none; };};

To configure the zone configuration file:

[[email protected] ~]# cd /var/named/[[email protected] named]# cp -p named.localhost wzn.com.zone[[email protected] named]# vim wzn.com.zone $TTL 1D@ IN SOA @ admin ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 192.168.100.200www IN A 192.168.100.200

Because the wzn01.com zone profile and the wzn.com are the same, the right copy can be reserved directly:

[[email protected] named]# cp -p wzn.com.zone wzn01.com.zone
Test

Restart the service and test:

[[email protected] named]# systemctl restart named[[email protected]CentOS7-1 named]# systemctl restart httpd


Three: Port-based virtual host

To create a configuration file with different port access:

[[email protected] ~]# vim /etc/httpd/conf.d/vhostport.conf                                //创建独立的配置文件<Directory /var/www/html>           //设置目录访问权限    Order allow,deny          Allow from all           </Directory>     NameVirtualHost 192.168.100.200:80  //设置虚拟主机监听地址<VirtualHost 192.168.100.200:80>    //设置wzn03虚拟站点区域   ServerAdmin [email protected]        //管理员邮箱   DocumentRoot /var/www/html/wzn03   //虚拟主机目录   ServerName www.wzn03.com           //域名   ErrorLog logs/wzn03.com-error_log  //错误日志   CustomLog logs/wzn03.com-access_log common //访问日志</VirtualHost>NameVirtualHost 192.168.100.200:8080<VirtualHost 192.168.100.200:8080>   ServerAdmin [email protected]   DocumentRoot /var/www/html/wzn04   ServerName www.wzn04.com   ErrorLog logs/wzn04.com-error_log   CustomLog logs/wzn04.com-access_log common</VirtualHost>

To prepare a Web page document for a virtual host:

[[email protected] ~]# mkdir /var/www/html/wzn03[[email protected] ~]# mkdir /var/www/html/wzn04[[email protected] ~]# echo "

To change the master profile add listening port 8080:

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf##省略部分信息#Listen 192.168.100.200:80Listen 8080 //添加 8080 端口
Test:

Restart the HTTPD service and access the different ports through the client:

[[email protected] ~]# systemctl restart httpd

Apache Server--a virtual web host based on different domain names on different ports

Related Article

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.