Apache配置虛擬主機

一、修改Apache主配置文件
html

[root@localhost ~]# vim /usr/local/apache2/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf

二、修改虛擬主機文件web

<VirtualHost *:80>
#    ServerAdmin webmaster@dummy-host.example.com
[root@localhost two.com]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
    DocumentRoot "/usr/local/apache2/htdocs/one.com"  //網頁文檔配置路徑
    ServerName www.one.com    //虛擬主機名稱
    ServerAlias www.1.com     //虛擬主機別名
</VirtualHost>
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache2/htdocs/two.com"
    ServerName www.two.com
    ServerAlias www.1.com
</VirtualHost>

三、建立網頁配置文件apache

[root@localhost htdocs]# mkdir one.com two.com
[root@localhost htdocs]# cd one.com
[root@localhost one.com]# echo "This is  first page" >index.html
[root@localhost htdocs]# cd two.com/
[root@localhost two.com]# echo "This is  second page" >index.html

四、測試vim

[root@localhost two.com]# /usr/local/apache2/bin/apachectl restart
[root@localhost two.com]# curl www.one.com
This is  first page
[root@localhost two.com]# curl www.two.com
This is  second page
相關文章
相關標籤/搜索