apache 配置虚拟主机

1.查找httpd.conf所在的位置

root@instance-baidu:/usr/local/apache/conf# sudo find / -name httpd.conf
/usr/local/apache/conf/httpd.conf

2.修改httpd.conf

vi /usr/local/apache/conf/httpd.conf

取消注释以下两行

LoadModule vhost_alias_module modules/mod_vhost_alias.so
Include conf/extra/httpd-vhosts.conf
查看虚拟主机配置文件位置
root@instance-baidu:/usr/local/apache/conf# cat extra/httpd-vhosts.conf Include /usr/local/apache/conf/vhost/*.conf
可以看到,虚拟主机文件在目录/usr/local/apache/conf/vhost

3.修改虚拟主机配置文件:vi vhost/default.conf

DocumentRoot 和 Directory 的值是相同的,即是子站的目录
<VirtualHost *:80>
DocumentRoot /data/www/default/zblog
ServerName zblog.com
<Directory /data/www/default/zblog>
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All
    Order Deny,Allow
    Allow from All
    DirectoryIndex index.php index.html index.htm
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /data/www/default/wordpress
ServerName uuu.com
<Directory /data/www/default/wordpress>
    SetOutputFilter DEFLATE
    Options FollowSymLinks
    AllowOverride All
    Order Deny,Allow
    Allow from All
    DirectoryIndex index.php index.html index.htm
</Directory>
</VirtualHost>

重启一下服务 service httpd restart

4.修改hosts文件做测试:

IP改为你自己的服务器IP,域名即为上面配置的servername

sudo vi /etc/hosts
127.111.39.58 zblog.com
127.111.39.58 uuu.com

posted @ 2020-03-15 09:26  船长博客  阅读(302)  评论(0编辑  收藏  举报
永远相信美好的事情即将发生!