Apache Build virtual Host (based on IP, port, domain name implementation) enclosing the source package

Source: Internet
Author: User
Tags nameserver nslookup

Brief introduction

Virtual host refers to a certain amount of disk space on the network server, the administrator can take advantage of this part of the space, put the site and application components, provide the necessary data storage and transmission functions. A virtual host is one that divides a physical server running on the Internet into multiple "virtual" servers.

Advantages

Low price. Compared to the purchase of a standalone server, the cost of website construction is greatly reduced, providing a great convenience for the popularization of small and medium-sized websites.
Improve efficiency. Because multiple virtual hosts share the resources of a real host, it greatly increases the utilization of the server and bandwidth, which makes it possible to configure multiple network IP addresses on a single server without conflict.

Disadvantages

Functional limitations. For example, may consume the system resources of the Forum program, traffic statistics function.
Access speed and traffic limits. The different virtual hosts on a single server are separate and managed by the administrator. However, a server host can only support a certain number of virtual hosts, and when this amount is exceeded, the server performance drops sharply.
The independence of the poor. Virtual host can not be arbitrarily installed by the customer software and Remote Desktop and other operations.

Use

Suitable as small and medium-sized web portal, save money resources.
Small and medium-sized enterprises, professional portals can use virtual host space to provide data sharing, data download services.
can provide the data storage data function for the SME. Because the cost is lower than the standalone server, high security is preferred as a small database.
The application templates that are unique to the virtual host space allow users to quickly deploy in batches and are the preferred platform for small and midsize businesses to run ASP or PHP applications.

Experimental environment
    • System Environment: centos6.5
    • Server IP Address: 192.168.100.103
    • Client IP Address: 192.168.100.99
    • Yum Mount directory:/mnt/sr0
    • Related source package: Baidu Cloud download? Password: PKO3
Build step one, prepare for work 1, close the firewall and SELinux

[Email protected] ~]# chkconfig iptables off #随开机关闭iptables
[Email protected] ~]# Vim/etc/sysconfig/selinux

[email protected] ~]# reboot #重启Linux生效

Second, build the DNS server 1, install the BIND package

[Email protected] ~]# cd/mnt/sr0/packages/
[Email protected] packages]# RPM-IVH bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm

2. Modify the master configuration file named.conf

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

3. Create and modify the DNS forward parsing file

[Email protected] ~]# cd/var/named/
[Email protected] named]# cp-p named.localhost bt.com.zone #将模板文件改为正向解析文件进行修改
[Email protected] ~]# Vim/var/named/bt.com.zone #修改正向解析文件

[Email protected] named]# cp-p bt.com.zone cloud.com.zone #搭建cloud域
[Email protected] ~]# Vim/var/named/bt.com.zone

4. Start the DNS server

[[email protected] ~]#/etc/init.d/named start

5. Modify the DNS client configuration file

[Email protected] ~]# echo "nameserver 192.168.100.103" >>/etc/resolv.conf

6. Test DNS resolution

[[email protected] ~]# nslookup www.bt.com #nslookup used to query DNS records to see if the domain name resolution is normal
[email protected] ~]# nslookup www.cloud.com

Third, install Apache1, install GCC, gcc-c++, make, ARP, Arp-util, Pcre and other toolkits

[Email protected] ~]# yum-y install gcc gcc-c++ make #安装C语言编译器以及make

[Email protected] ~]# TAR-ZXVF apr-1.4.6.tar.gz-c/usr/src/
[Email protected] ~]# cd/usr/src/apr-1.4.6/
[[email protected] apr-1.4.6]#./configure prefix=/usr/local/apr && make && make install

[Email protected] ~]# TAR-ZXVF apr-util-1.4.1.tar.gz-c/usr/src/
[Email protected] ~]# CD/USR/SRC/APR-UTIL-1.4.1/
[Email protected] apr-util-1.4.1]#/configure prefix=/usr/local/apr-util--with-apr=/usr/local/apr && Make & amp;& make Install

[Email protected] ~]# TAR-ZXVF pcre-8.10.tar.gz-c/usr/src #支持正则
[Email protected] ~]# cd/usr/src/pcre-8.10/
[Email protected] pcre-8.10]#/configure prefix=/usr/local/pcre && make && make instal

2. Configuring and installing Apache

[Email protected] ~]# tar xvfz httpd-2.4.2.tar.gz-c/usr/src/
[Email protected] ~]# cd/usr/src/httpd-2.4.2/
[Email protected] httpd-2.4.2]#/configure \
--PREFIX=/USR/LOCAL/HTTPD \
--WITH-APR=/USR/LOCAL/APR \
--with-pcre=/usr/local/pcre \
--ENABLE-SO \
--enable-rewrite \
--enable-mods-shared=most \
--with-mpm=worker \
--disable-cgid \
--disable-cgi

Parameter resolution:
Prefix: Specifying the installation directory
installation directory for WITH-APR:APR
With-pcre: Using the extended pcre regular expression Library
ENABLE-SO: Enable dynamic load module support, what functions are required to dynamically load
Enable-rewrite: Enable Web address rewriting to implement pseudo-static
Enable-mods-shared: Enabled shared DSO module
WITH-MPM: Select the processing module that Apache uses
Disable-cgid: Disable Cgid
DISABLE-CGI: Enable CGI script support (Universal Gateway Interface)

[[email protected] httpd-2.4.2]# make && make install

3. Adding system Services

[Email protected] ~]# CP/USR/LOCAL/HTTPD/BIN/APACHECTL/ETC/INIT.D/HTTPD

[Email protected] ~]# VIM/ETC/INIT.D/HTTPD

Lines 2nd, 32 add the following parameters
# chkconfig:2345 85 15
# Description:apache is a world Wide Web server.

[Email protected] init.d]# chmod +x/etc/init.d/httpd
[Email protected] init.d]# chkconfig--add httpd

4, the establishment of soft links, easy to manage

[Email protected] ~]# mkdir-p/etc/httpd
[Email protected] ~]# ln-s/usr/local/httpd/conf//etc/httpd/#优化配置文件路径
[Email protected] ~]# ln-s/usr/local/httpd/bin/*/usr/local/bin/#优化命令路径

5. Modify the configuration file

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

#修改以下参数:
ServerName www.bt.com:80 #填写完全主机名
Listen 192.168.100.103:80 #监听本地IP

6. Restart Service, test

[[Email protected] ~]# service httpd start

Four, domain-based virtual host (same IP, same port, different hostname) 1, create virtual Web host Site Directory and Web page

[Email protected] ~]# mkdir-p/var/www/html/{btcom,cloudcom} #创建网站目录
[Email protected] ~]# echo "This is bt.com aaaaaaaaaa" >/var/www/html/btcom/index.html #创建网页
[Email protected] ~]# echo "This is cloud.com bbbbbbbbbb" >/var/www/html/cloudcom/index.html #创建网页

2, modify the configuration file, add the virtual host configuration

[Email protected] ~]# vim/etc/httpd/conf/httpd.conf #修改主配置文件

Modify and open the following parameters:
Include conf/extra/httpd-vhosts.conf #打开此行注释, covers the configuration of the virtual host, and can be seen in the Conf directory with the virtual host configuration file
<directory/> #定义 "/" Directory area
Options followsymlinks #控制选项, allowing symbolic connections to be used
AllowOverride None #不允许隐含
Order Deny,allow #以下两行允许所有人访问
Allow from all
</Directory>

[Email protected] ~]# vim/etc/httpd/conf/extra/httpd-vhosts.conf #编辑虚拟主机配置

Modify and add the following parameters:
<directory "/var/www/html" > #定义网站目录允许所有人访问
Order Allow,deny
Allow from all
</Directory>

#NameVirtualHost 192.168.100.103 #配置指定提供虚拟主机服务的IP地址, that is, the domain name query when the virtual Web host IP address, pay attention to!!!!!!!!! I installed the 2.2 version of the time is required to use this item, but now installed 2.4 version does not need to install the error.

<virtualhost 192.168.100.103>
ServerAdmin [email protected] #设置管理员邮箱地址
DocumentRoot "/var/www/html/btcom" #设置站点目录
ServerName www.bt.com #完全主机名
Serveralias www.bt.com #完全主机名别名
Errorlog "Logs/www.bt.com-error_log" #错误日志存放位置
Customlog "Logs/www.bt.com-access_log" Common #访问日志存放位置
</VirtualHost>

<virtualhost 192.168.100.103>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/cloudcom"
ServerName www.cloud.com
Serveralias www.cloud.com
Errorlog "Logs/www.cloudcom.com-error_log"
Customlog "Logs/www.cloudcom.com-access_log" common
</VirtualHost>

3. Client Testing

[Email protected] ~]# echo "nameserver 192.168.100.103" >>/etc/resolv.conf #修改DNS客户机配置文件

Five, IP address-based virtual host (same port, same hostname, different IP) 1, add a network card server side eth1

2. Modify the master configuration file

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

#添加, modify the following two lines of parameters:
Listen 192.168.100.103:80
Listen 192.168.100.104:80

3. Modify the virtual host configuration file

[Email protected] ~]# vim/etc/httpd/conf/extra/httpd-vhosts.conf

<directory "/var/www/html" >
Order Allow,deny
Allow from all
</Directory>

<virtualhost 192.168.100.103>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/btcom"
ServerName www.bt.com
Serveralias www.bt.com
Errorlog "Logs/www.bt.com-error_log"
Customlog "Logs/www.bt.com-access_log" common
</VirtualHost>

<virtualhost 192.168.100.104>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/cloudcom"
ServerName www.bt.com
Serveralias www.bt.com
Errorlog "Logs/www.cloudcom.com-error_log"
Customlog "Logs/www.cloudcom.com-access_log" common
</VirtualHost></VirtualHost>

4. Restart HTTPD Service

[Email protected] ~]#/etc/init.d/httpd restart

VI, Port-based virtual host (same port, same hostname, different IP) 1, modify the virtual host configuration file

[Email protected] ~]# vim/etc/httpd/conf/extra/httpd-vhosts.conf

<directory "/var/www/html" >
Order Allow,deny
Allow from all
</Directory>

<virtualhost 192.168.100.103:80>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/btcom"
ServerName www.bt.com
Serveralias www.bt.com
Errorlog "Logs/www.bt.com-error_log"
Customlog "Logs/www.bt.com-access_log" common
</VirtualHost>

<virtualhost 192.168.100.103:8080>
ServerAdmin [email protected]
DocumentRoot "/var/www/html/cloudcom"
ServerName www.cloud.com
Serveralias www.cloud.com
Errorlog "Logs/www.cloudcom.com-error_log"
Customlog "Logs/www.cloudcom.com-access_log" common
</VirtualHost></VirtualHost>

2. Modify the master configuration file

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

#以下两行要有, and I'll comment out the IPV6 's listening
Listen 192.168.100.103:80
Listen 192.168.100.103:8080

3. Restart HTTPD Service

[Email protected] ~]#/etc/init.d/httpd restart

4. Client Testing

Apache Build virtual Host (based on IP, port, domain name implementation) enclosing the source package

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.