Running multiple Web sites in the same Apache server, each of which does not actually occupy the entire server, can take advantage of the server's hardware resources through virtual web hosting services, reducing site build and operating costs. The main types of virtual host are divided into three kinds:
1, based on IP port
For each different domain name of the virtual host set up a separate IP, therefore, in the server needs to set up a number of network cards, for hardware costs and IP cost requirements are high, this method is not commonly used in practice, this text is omitted;
2. Port-based IP
The use of different TCP ports to distinguish between different site content, you need to keep up with the specified port number when users visit the site to achieve access;
3, based on host name
Each server host can build several different name servers, but all use the same IP address, which is more commonly used in practice!
When the content of the Web page is more, for the background operation and maintenance of data processing and updating pressure, it is necessary to establish a directory of classification management, convenient management, known as virtual directory;
Experiment Description:
- Experimental environment Redhat6.5 version
- Server IP Address: 192.168.100.107
- Redhat mirroring mounted to/mnt
- This experiment uses the Apache2.2 version
Rpm-q httpd//view Apache version
Environment deployment
Rpm-q httpd//Check if Apache is installed
Service iptables stop//firewall off
Setenforce 0//Off Enhanced security XXX
Establish Apache virtual directory (User access control) 1, virtual directory Access
RPM-IVH/MNT/PACKAGES/HTTPD-2.2.15-29.EL6_4.X86_64.RPM//Installation Apache2.2
vim/etc/httpd/conf/httpd.conf//Edit Master Profile
Listen 192.168.100.107:80 //更改监听地址和监听端口#Listen 80 //注释IPV6的监听...ServerName www.yun.com:80 //打开主机域名
Vim/etc/httpd/conf.d/vdir.conf
Create a virtual directory configuration file under the sub-profile directory vdir.conf
Write the following in vdir.conf:
Alias /test "/opt/test/" //指定虚拟目录名称为test,并指定目录站点在/opt/test<Directory "/opt/test/"> Options Indexes MultiViews FollowSymLinks AllowOverride None AuthName "hello" //认证名称 authtype basic //用户认证方式为基本认证方式 authuserfile /etc/httpd/user //指定用户认证文件存放位置 #authgroupfile /etc/httpd/group #require Valid-user //设置用户访问权限,取消注释时即可实现用户授权访问; #require user test #Require group admin</Directory>
Mkdir-p/opt/test//Create a virtual directory site
vim/opt/test/index.html//Create a virtual directory home
Service httpd start//Open HTTPd Services
2. User authorized Access
vim/etc/httpd/conf.d/vdir.conf//Edit Service sub-profile
Alias /test "/opt/test/" //指定虚拟目录名称为test,并指定目录站点在/opt/test<Directory "/opt/test/"> Options Indexes MultiViews FollowSymLinks AllowOverride None AuthName "hello" //认证名称 authtype basic //用户认证方式为基本认证方式 authuserfile /etc/httpd/user //指定用户认证文件存放位置 #authgroupfile /etc/httpd/group #require Valid-user //取消注时即可实现用户授权访问; #require user test #Require group admin</Directory>
Htpasswd-c/etc/httpd/user Zhangsan//Create an authorized access user
Service httpd restart//restart HTTPD services
When you visit a webpage again, you become a user who needs authorization to access it:
same IP different port 1, configuring DNS
See also: DNS Domain name Resolution service configuration
RPM-IVH/MNT/PACKAGES/BIND-9.8.2-0.17.RC1.EL6_4.6.X86_64.RPM//First install DNS domain name Resolution Service
VIM/ETC/NAMED.CONF//Configure domain name resolution master configuration file
options { listen-on port 53 { 192.168.100.107; }; //监听端口主机IP 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; }; //允许任意网段主机都可解析 recursion yes;
Vim/etc/named.rfc1912.zones//Edit Zone Profile
zone "yun.com" IN { type master; file "yun.com.zone"; allow-update { none; };};
cd/var/named//Switch to the zone data configuration directory
Cp-p named.localhost yun.com.zone//Copy area Data profile template
VIM Yun.com.zone//Configure zone Data profile
$TTL 1D@ IN SOA @ admin. ( //修改管理员邮箱 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.100.107 //设置解析地址
Service named start//Turn on DNS services
2. Different contents of different ports
vim/etc/httpd/vhost.conf//Create a virtual host port configuration file
Write the following content:
NameVirtualHost 192.168.100.107:80 //设置主机IP及端口号<VirtualHost 192.168.100.107:80> ServerAdmin [email protected] DocumentRoot /opt/yun/ //设置80端口网页站点 ServerName www.yun.com //解析域名 ErrorLog logs/yun.com-error_log //错误日志存放位置 CustomLog logs/yun.com-access_log common //访问日志存放位置</VirtualHost>NameVirtualHost 192.168.100.107:250<VirtualHost 192.168.100.107:250> ServerAdmin [email protected] DocumentRoot /opt/yun01/ //设置80端口网页站点 ServerName www.yun.com //解析域名 ErrorLog logs/yun01.com-error_log //错误日志存放位置 CustomLog logs/yun01.com-access_log common //访问日志存放位置</VirtualHost>
Mkdir-p/opt/yun//Create a 80-port site
echo "Yun Port test Web" >/opt/yun/index.html//Create www.yun.com:80 home page content
Mkdir-p/opt/yun01//Create a 250-port site
echo "Yun Port test Web" >/opt/yun01/index.html//Create www.yun.com:250 home page content
vim/etc/httpd/conf/httpd.conf//Edit httpd service master configuration file
Listen 192.168.100.107:80 //原有监听端口Listen 192.168.100.107:250 //添加监听端口
Service httpd restart//restart HTTPD services
Service named restart//Restart DNS service
Different content occurs when accessing different ports of the same IP domain name:
same IP different host 1, configure DNS Resolution service
Vim/etc/named.rfc1912.zones//Edit Zone Profile
zone "yun.com" IN { type master; file "yun.com.zone"; allow-update { none; };};zone "abc.com" IN { //添加新的解析域名 type master; file "abc.com.zone"; allow-update { none; };};
Cd/var/named
Cp-p yun.com.zone abc.com.zone//Copy area Data profile template
Vim Abc.com.zone
$TTL 1D@ IN SOA @ admin. ( 0 ; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS @ A 127.0.0.1www IN A 192.168.100.107
2. Different host
Vim/etc/httpd/conf.d/vhost.conf
Add the following content:
<VirtualHost 192.168.100.107:80> ServerAdmin [email protected] DocumentRoot /opt/abc/ ServerName www.abc.com ErrorLog logs/abc.com-error_log CustomLog logs/abc.com-access_log common</VirtualHost>
Mkdir-p/OPT/ABC//Create a www.abc.com site
echo "This is ABC" >/opt/abc/index.html//create Content
Service httpd restart//restart HTTPD services
Service named restart//Restart DNS service
Apache Build web Hosting