1.win访问linux:在win的hosts文件中添加
#配置lanmp192.168.106.141 www.cd.pro测试:ping 192.168.106.141应该可以ping通
2.配置linux中访问本地主机:需要在hosts文件与hostname中设置 centos7的要求
[root@localhost sites-enabled]# cat /etc/hosts127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4::1 localhost localhost.localdomain localhost6 localhost6.localdomain6127.0.0.1 www.cd.pro
[root@localhost sites-enabled]# cat /etc/hostname localhost.localdomainwww.cd.pro
此时在win下面 ping www.cd.pro 应该可以ping通进行curl www.cd.pro应该可以通过 出现httpd.conf设置的默认页面!
3.配置虚拟主机:没有配置的话 默认访问httpd.conf中的;
我们先进行添加配置文件
sites-avaliable是用来设置所有的conf的,我们要激活的加个软连接ln -s 添加到到sites-enables里面去(httpd.conf里面有include site-enables文件夹的代码)
这两个文件夹都是自己新建的哈,
4.配置虚拟主机:新建配置文件ex.conf
[root@localhost sites-available]# cat ex.conf <VirtualHost *:80> ServerName www.cd.proDocumentRoot /var/www//public_htmlErrorLog /var/www//error.logCustomLog /var/www//requests.log combined<Directory "/var/www//public_html">#允许重写AllowOverride AllOrder allow,denyAllow from all#授权所有的访问Require all granted</Directory></VirtualHost>
加个软连接到sites-enabled里面去ln -s ./ex.conf ../sites-enabled/ex.conf
在/var/www//public_html新建index.html文件!
5.进行重启apache 加载配置文件
[root@localhost bin]# /usr/local/apache/bin/apachectl stop[root@localhost bin]# /usr/local/apache/bin/apachectl start
6.测试linux本地
curl www.cd.pro
7.测试win本地
浏览器访问即可了!