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

Source: Internet
Author: User

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


Apache Virtual host implementations are available in three ways:

1. Through different IP addresses

2, through the different domain name

3, through a different port number


three need to open the virtual host function :

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

Change:

#NameVirtualHost *:80

For:

Namevirtualhost *:80

Method 1: Resolve different domain names with different IP addresses

Add IP to the server (another domain name resolution)

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

[Email protected] ~]# Mkdir/var/www/html/bbs

[Email protected] ~]# echo "bbs.xuegod.cn" >/var/www/html/bbs/index.html

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

Modify Httpd.conf

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

<virtualhost 192.168.1.63:80>

ServerAdmin [email protected]

documentroot/var/www/html/

ServerName www.xuegod.cn

Errorlog Logs/www.xuegod.cn-error_log

Customlog Logs/www.xuegod.cn-access_log Common

</VirtualHost>

<virtualhost 192.168.1.65:80>

ServerAdmin [email protected]

documentroot/var/www/html/bbs/

ServerName bbs.xuegod.cn

Errorlog Logs/bbs.xuegod.cn-error_log

Customlog Logs/bbs.xuegod.cn-access_log Common

</VirtualHost>


Method 2: Configure the virtual host with a different domain name

#vim httpd.conf

Change: #NameVirtualHost *:80

Namevirtualhost 192.168.1.63

<virtualhost www.xuegod63.cn>

ServerAdmin [email protected]

documentroot/var/www/html/

ServerName www.xuegod.cn

Errorlog Logs/www.xuegod.cn-error_log

Customlog Logs/www.xuegod.cn-access_log Common

</VirtualHost>

<virtualhost bbs.xuegod63.cn>

ServerAdmin [email protected]

documentroot/var/www/html/bbs/

ServerName bbs.xuegod.cn

Errorlog Logs/bbs.xuegod.cn-error_log

Customlog Logs/bbs.xuegod.cn-access_log Common

</VirtualHost>

[Email protected] ~]# vim/etc/hosts

192.168.1.63 www.xuegod63.cn

192.168.1.63 bbs.xuegod63.cn

Restart Service

Service httpd Restart

Verify:

http://www.xuegod63.cn

http://bbs.xuegod63.cn


Method 3: Configure the virtual host with different ports

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

Change:

Listen 80

For:

Listen 80

Listen 8080

#更改为你要添加的端口

Create 2 more Virtual hosts

<virtualhost *:80>

ServerAdmin [email protected]

documentroot/var/www/html/

ServerName www.xuegod.cn

Errorlog Logs/www.xuegod.cn-error_log

Customlog Logs/www.xuegod.cn-access_log Common

</VirtualHost>

<virtualhost *:8080>

ServerAdmin [email protected]

documentroot/var/www/html/bbs/

ServerName bbs.xuegod.cn

Errorlog Logs/bbs.xuegod.cn-error_log

Customlog Logs/bbs.xuegod.cn-access_log Common

</VirtualHost>

Restart Service

Service httpd Restart

Verify:

http://192.168.1.63

http://192.168.1.63:8080


This article is from the "Innocence" blog, be sure to keep this source http://innocence.blog.51cto.com/4313888/1963374

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.