Configure Apache Virtual host to run multiple Web sites on a single server

Source: Internet
Author: User

Apache There are three ways to implement a virtual host:

1 , through a different IP address

2 , through a different domain name

3 , through a different port number

1 , resolving different domain names through different IP addresses

(1) Add IP to the server (another domain name resolution)

[Email protected] ~]# ifconfig eth0:1 192.168.2.12

View Add success

(2) Create a test file

[Email protected] ~]# cd/var/www/html/

[Email protected] html]# mkdir Hongkong

[Email protected] html]# echo "www.hongkong.cn" >/var/www/html/hongkong/index.html

[Email protected] html]# echo "www.xianggang.cn" >/var/www/html/index.html

(3) Modify the httpd.conf configuration file

[[email protected] HTML] #vim/etc/httpd/conf/httpd.conf

Change:

993 line #NameVirtualHost *:80

For:

Namevirtualhost *:80

1006 <virtualhost 192.168.2.101:80>

1007 ServerAdmin [email protected]

1008 documentroot/var/www/html/

1009 ServerName www.xianggang.cn

1010 Errorlog Logs/www.xianggang.cn-error_log

1011 Customlog Logs/www.xianggang.cn-access_log Common

1012 </VirtualHost>

1013 <virtualhost 192.168.2.12:80>

1014 ServerAdmin [email protected]

1015 documentroot/var/www/html/hongkong/

1016 ServerName www.hongkong.cn

1017 Errorlog Logs/www.hongkong.cn-error_log

1018 Customlog Logs/www.hongkong.cn-access_log Common

1019 </VirtualHost>


(4) Restart service

Service httpd Restart

(5) Test:

2 , configure a virtual host with a different domain name

(1) Modify the httpd.conf configuration file

[[email protected] HTML] #vim/etc/httpd/conf/httpd.conf

Change:

993 line #NameVirtualHost *:80

For

Namevirtualhost 192.168.1.63

1007 <virtualhost Www.xianggang.cn>

1008 ServerAdmin [email protected]

1009 documentroot/var/www/html/

1010 ServerName www.xianggang.cn

1011 Errorlog Logs/www.xianggang.cn-error_log

1012 Customlog Logs/www.xianggang.cn-access_log Common

1013 </VirtualHost>

1014 <virtualhost www.hongkong.cn>

1015 ServerAdmin [email protected]

1016 documentroot/var/www/html/hongkong/

1017 ServerName www.hongkong.cn

1018 Errorlog Logs/www.hongkong.cn-error_log

1019 Customlog Logs/www.hongkong.cn-access_log Common

1020 </VirtualHost>

(2) Restart service

[Email protected] html]# service httpd restart

(3) Modify the computer Hosts file C:\Windows\System32\drivers\etc\hosts for analysis:

192.168.1.63 www.xianggang.cn

192.168.1.63 www.hongkong.cn

(4) Because the virtual administrator account can modify the WIN10 hosts file so do not test demo

3 : Configure a virtual host with a different port

(1) [[email protected] html]# vim/etc/httpd/conf/httpd.conf

# Change to the port you want to add

Change:

136 Row Listen 80
are:

Listen 80

Listen 8080

(2) Create 2 more virtual hosts

1007 <virtualhost *:80>

1008 ServerAdmin [email protected]

1009 documentroot/var/www/html/

1010 ServerName www.xianggang.cn

1011 Errorlog Logs/www.xianggang.cn-error_log

1012 Customlog Logs/www.xianggang.cn-access_log Common

1013 </VirtualHost>

1014 <virtualhost *:8080>

1015 ServerAdmin [email protected]

1016 documentroot/var/www/html/hongkong/

1017 ServerName www.hongkong.cn

1018 Errorlog Logs/www.hongkong.cn-error_log

1019 Customlog Logs/www.hongkong.cn-access_log Common

1020 </VirtualHost>

Restart Service

Service httpd Restart

Verify:

Http://192.168.2.101

http://192.168.2.101:8080



Apache Service Foundation Tuning Parameters detailed reference links: http://blog.51cto.com/13719714/2109007


Configure Apache Virtual host to run multiple Web sites on a single server

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.