Apache Build virtual web Host

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

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

ApacheThe main features:
    • Open Source Code
    • Cross-platform applications
    • Supports a variety of Web programming languages
    • Modular design
    • Very stable operation
    • Good security

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 virtual host without domain name set up a separate IP, so, in the server need to set up multiple network cards, for hardware costs and IP cost requirements are high, this method is not used in practice, this article for the moment.
    2. Port-based IP
      Using TCP without ports to differentiate unused site content requires that access be followed by the specified port number when the user accesses the site.
    3. Based on host name
      Each server host can build multiple servers without a domain name, but all use the same IP address, which is more commonly used in practice.
Lab Environment:
    • RHEL6.5 Operating System
    • Server IP Address: 192.168.100.110
    • Rhel mirrored discs mounted to the/MNT directory
Environment deployment 1. Check and install the HTTPD server
rpm -q httpd               //检查httpd服务器是否已安装httpd-2.2.15-29.el6_4.x86_64                   //已安装httpd服务器
2. Turn off the firewall and enhance security features
service iptables stopsetenforce 0
Build Apache virtual directory (user access control)
vim /etc/httpd/conf/httpd.conf           //编辑httpd配置文件

Listen 192.168.100.110:80//change the listening address and listening port
#Listen 80//Note IPV6 monitoring
ServerName www.yun.com:80//Set host name

vim /etc/httpd/conf.d/vdir.conf //在子配置目录下创建虚拟目录配置文件vdir.conf

The following is a write to the content in vdir.conf
Alias/test "/opt/test/"//Set Alias
<directory "/opt/test/" >//define Virtual directory
Options Indexes multiviews FollowSymLinks
AllowOverride None
AuthName "Hello"//Authentication Name
AuthType Basic//Fundamental authentication method
Authuserfile/etc/httpd/user//Specify user authentication file storage location
#authgroupfile/etc/httpd/group
#require valid-user//Set User access rights
#require User Test
#Require Group Admin
</Directory>

mkdir –p /opt/test          //创建虚拟目录站点      echo “this is vdir test” > /opt/test/index.html     //新建站点首页  service httpd start     //开启httpd服务

User Authorized access:
vim /etc/httpd/conf.d/vdir.conf     //编辑服务子配置文件

<directory "/opt/test/" >//define Virtual directory
Options Indexes multiviews FollowSymLinks
AllowOverride None
AuthName "Hello"//Authentication Name
AuthType Basic//Fundamental authentication method
Authuserfile/etc/httpd/user//Specify user authentication file storage location
#authgroupfile/etc/httpd/group
Require Valid-user//set User access rights
#require User Test
#Require Group Admin
</Directory>

htpasswd –c /etc/httpd/user zhangsan            //创建授权访问用户zhangsanservice httpd restart               //重启httpd服务

When you visit the webpage again, you will get out of the Account password Verification login window:

The same IP different port case: 1. Create a new vport.conf (virtual directory file) under the/ETC/HTTPD/CONF.D directory
cd /etc/httpd/conf.d/vim vport.conf                  //新建vport.conf配置文件

Write the following content:

Namevirtualhost 192.168.100.110:80//virtual host IP address and port number
<virtualhost 192.168.100.110:80>
ServerAdmin [email protected]//admin mailbox
documentroot/opt/yun///Web Site Directory
ServerName www.yun.com//Domain name
Errorlog logs/benet.com-error_log//error log
Customlog Logs/benet.com-access_log common//access log
</VirtualHost>
Namevirtualhost 192.168.100.110:81//virtual host IP address and port number
<virtualhost 192.168.100.110:81>
ServerAdmin [email protected]//admin mailbox
DOCUMENTROOT/OPT/YUN01///Web Site Directory
ServerName www.yun.com//Domain name
Errorlog logs/benet.com-error_log//error log
Customlog Logs/benet.com-access_log common//access log
</VirtualHost>

2. Create Yun, yun01 Site Directory, new site home page file
mkdir /opt/yun /opt/yun01       //创建站点目录echo ”yun port 80 test” > /opt/yun/index.html   //添加yun站点的首页内容echo ”yun01 port 81 test” > /opt/yun01/index.html  //添加yun01站点的首页内容
3. Modify the httpd.conf configuration file
vim /etc/httpd/conf/httpd.confListen 192.168.100.110:81           //添加81端口的监听地址
4. Restart the HTTPD service
service httpd restart
5. Testing


The same IP different host case: 1. Create a new vhost.conf under the/ETC/HTTPD/CONF.D directory
cd /etc/httpd/conf.d/vim vhost.conf          //新建vhost.conf配置文件

Write the following content:

Namevirtualhost 192.168.100.110:80//Virtual host name
<virtualhost 192.168.100.110:80>
ServerAdmin [email protected]//admin mailbox
documentroot/opt/benet///Site Directory
ServerName www.benet.com//Domain name
Errorlog logs/benet.com-error_log//error log
Customlog Logs/benet.com-access_log common//access log
</VirtualHost>

mkdir /opt/benet            //创建www.benet.com的站点echo “this is benet” > /opt/benet/index.html        //创建首页及添加内容
2. Install the DNS server

To install the BIND package:

rpm –ivh /mnt/Packages/bind-9.8.2-0.17.rc1.el6_x86_64.rpm

Edit the master configuration file

vim /etc/named.conf

Options {
Listen-on Port 53 {192.168.100.110;};
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;

Editing a zone configuration file

vim /etc/named.rfc1912.zones

Zone "Yun.com" in {
Type master;
File "Yun.com.zone";
allow-update {none;};
};

Zone "Benet.com" in {
Type master;
File "Benet.com.zone";
allow-update {none;};
};

Copy template files under the/var/named directory

cd /var/namedcp –p named.localhost yun.com.zone

Edit a zone data configuration file

vim yun.com.zone

cp –p yun.com.zone benet.com.zone     //yun和benet区域数据配置文件相同,可直接复制

3. Start (restart) named and httpd services:

service httpd restartservice named start

4. Testing


Apache Build virtual web Host

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.