Linux下Apache配置虚拟主机

在/etc/hosts添加域名解析
127.0.0.1   www.king.org
127.0.0.1   blog.king.org
127.0.0.1   bbs.king.org

1)配置基于域名的虚拟主机

在httpd.conf中启动httpd-vhosts.conf

Include conf/extra/httpd-vhosts.conf

添加一下内容,对虚拟主机的目录授权

<Directory "/var/www/web">
    Options  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>


<Directory "/var/www/bbs">
    Options  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>
<Directory "/var/www/blog">
    Options  FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>


2.在conf/extra/httpd-vhosts.conf中添加以下内容

<VirtualHost *:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/web"
    ServerName www.king.org
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/bbs"
    ServerName bbs.king.org
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common
</VirtualHost>


<VirtualHost *:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/blog"
    ServerName blog.king.org
    ServerAlias blog.org
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common
</VirtualHost>


2.基于端口的虚拟主机

在httpd.conf中添加两行

Listen 8000

Listen 9000

<VirtualHost *:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/web"
    ServerName www.king.org
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common
</VirtualHost>


<VirtualHost *:8000>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/bbs"
    ServerName bbs.king.org
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common
</VirtualHost>


<VirtualHost *:9000>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/blog"
    ServerName blog.king.org
    ServerAlias blog.org
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common
</VirtualHost>


httpd -k graceful

netstat -tlunp|grep -E "8000|9000"
tcp        0      0 :::8000                     :::*                        LISTEN      89128/httpd         
tcp        0      0 :::9000                     :::*                        LISTEN      89128/httpd 


3.基于IP的虚拟主机

ifconfig eth0:0 192.168.1.118/24 up

<VirtualHost 192.168.1.115:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/web"
    ServerName 192.168.1.115
    ServerAlias king.org
    ErrorLog "logs/web-error_log"
    CustomLog "logs/web-access_log" common
</VirtualHost>


<VirtualHost 192.168.1.118:80>
    ServerAdmin 185604832@qq.com
    DocumentRoot "/var/www/bbs"
    ServerName 192.168.1.118
    ServerAlias bbs.org
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common
</VirtualHost>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值