Linux中一个ip绑定多个域名的详细步骤
操作平台:Centos 7建议:执行本文操作前,请对linux系统先拍照存档,以免造成操作过程中出现错误,导致重装linux系统的尴尬!上菜!上菜!1.指定IP地址与域名之间的对应关系[root@localhost ~]# vim /etc/hosts该处ip后跟的域名可随意写,但是不要与网络上现有的域名重名!注意: 该处输入的ip地址是我本机电脑ip地址2.使用ping命令检查域名解析ping
·
操作平台:Centos 7
建议:执行本文操作前,请对linux系统先拍照存档,以免造成操作过程中出现错误,导致重装linux系统的尴尬!
上菜!上菜!
1.指定IP地址与域名之间的对应关系
[root@localhost ~]# vim /etc/hosts
该处ip后跟的域名可随意写,但是不要与网络上现有的域名重名!
注意: 该处输入的ip地址是我本机电脑ip地址
2.使用ping命令检查域名解析
ping www.wb.com
ping www.wwbb.com
注:出现“64 bytes from......”说明可以查到,等它刷新两行即可关闭,需要手动关闭ping命令"ctrl+c"
3. 创建存放不同网站的根目录,并写入网站首页内容
[root@localhost ~]# mkdir -p /home/yuming/wb
[root@localhost ~]# mkdir -p /home/yuming/wwbb
[root@localhost ~]# echo "该网站域名是www.wb.com" > /home/yuming/wb/index.html
[root@localhost ~]# echo "该网站域名是www.wwbb.com" > /home/yuming/wwbb/index.html
4.修改主配置文件
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
把下面代码写进配置文件中(注:修改为自己的ip地址)
<VirtualHost 192.168.37.129>
DocumentRoot /home/yuming/wb
ServerName www.aaa.com
<Directory "/home/yuming/wb">
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
<VirtualHost 192.168.37.129>
DocumentRoot /home/yuming/wwbb
ServerName www.bbb.com
<Directory "/home/yuming/wwbb">
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
5.重启httpd服务
[root@localhost ~]# systemctl restart httpd
6.修改自定义网站目录的Selinux文件安全上下文
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/yuming
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/yuming/wb
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/yuming/wb/*
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/yuming/wwbb
[root@localhost ~]# semanage fcontext -a -t httpd_sys_content_t /home/yuming/wwbb/*
7. 刷新Selinux安全上下文,使其立即生效
[root@localhost ~]# restorecon -Rv /home/yuming
8.使用域名测试网站
注意:此处查询不能在windows系统中查询,需要在linux系统中的FireFox中查询
出现该界面,则操作成功!
到此,一个ip绑定多个域名操作全部完成!
更多推荐
已为社区贡献1条内容
所有评论(0)