linux apache下虚拟主机配置方法
程序员文章站
2022-04-28 15:59:28
假设vps的ip是58.130.17.168,有两个域名指向该ip,分别是domain1.com, domain2.com, &...
假设vps的ip是58.130.17.168,有两个域名指向该ip,分别是domain1.com, domain2.com,
修改/etc/httpd/conf/httpd.conf,在文件的最后加入:
servername 58.130.17.168
namevirtualhost 58.130.17.168
<virtualhost 58.130.17.168>
servername domain1.com
documentroot /var/www/domain1.com
<directory "/var/www/domain1.com">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 58.130.17.168>
servername domain2.com
documentroot /var/www/domain2.com
<directory "/var/www/domain2.com">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
然后在/var/www/domain1.com和/var/www/domain2.com下创建不同的index.html文件:
echo "domain1">/var/www/domain1.com/index.html
echo "domain2">/var/www/domain2.com/index.html
在浏览器里输入http://domain1.com和http://domain2.com即可看到效果了
修改/etc/httpd/conf/httpd.conf,在文件的最后加入:
servername 58.130.17.168
namevirtualhost 58.130.17.168
<virtualhost 58.130.17.168>
servername domain1.com
documentroot /var/www/domain1.com
<directory "/var/www/domain1.com">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
<virtualhost 58.130.17.168>
servername domain2.com
documentroot /var/www/domain2.com
<directory "/var/www/domain2.com">
options indexes followsymlinks
allowoverride none
order allow,deny
allow from all
</directory>
</virtualhost>
然后在/var/www/domain1.com和/var/www/domain2.com下创建不同的index.html文件:
echo "domain1">/var/www/domain1.com/index.html
echo "domain2">/var/www/domain2.com/index.html
在浏览器里输入http://domain1.com和http://domain2.com即可看到效果了