centos绑定多个域名
大家讲道理
大家讲道理 2017-04-25 09:01:16
[Linux讨论组]

正在使用aliyun主机,运行centos6.4 64位系统,安装lamp环境后进行域名绑定。配置文件如下:

<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName 120.24.54.xxx
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/domain1
    ServerName domain.com
    ServerAlias *.domain.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /var/www/html/domain2
    ServerName domain.com
    ServerAlias *.domain.com
</VirtualHost>

然后通过www.domain1.com可以访问指向/var/www/html/domain1目录的网站,但是通过www.domain1.com访问同样是指向/var/www/html/domain1,通过IP 120.24.54.xxx访问也是指向domai1目录,配置文件其他地方没动过。我想要通过IP访问就指向html目录,通过域名访问就指向对应的目录。

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复(3)
黄舟

通过查看官方文档已经找到答案:
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/example1
ServerName www.example.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/example2
ServerName www.example.org

# Other directives here

</VirtualHost>

必须开启NameVirtualHost *:80,否则无论绑定多少个域名,全部都会指向第一个virtualhost的documentroot

PHPz

修改配置过后你重启apache了么?
还有确定你的vhost mod开启了么?

怪我咯


DocumentRoot /var/www/html/domain1
ServerName domain.com
ServerAlias *.domain.com


DocumentRoot /var/www/html/domain2
ServerName domain.com
ServerAlias *.domain.com

这里没改掉了?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号