检查步骤如下:
1、nginx -t ,检查配置文件是否有语法错误
[root@89 ~]# nginx -t
nginx: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /opt/nginx/conf/nginx.conf test is successful
# 可以看到 配置文件语法无误
# 域名虚拟主机 配置如下
server {
listen 80;
server_name curl www.only2u.com; # 自定义的域名
location / {
root html/only_vm1; # 站点根目录
index 1.html; #首页文件
}
}
2、curl 一下
[root@89 ~]# curl www.only2u.com
<!DOCTYPE html>
<html><h1>test1</h1
>
</html># 可以看到,也没有问题。
注意,curl这一步 如果想要实现,需提前修改/etc/hosts文件,添加内容如windows的hosts一样。
3 来到windows主机,使用浏览器访问
前提: 已修改 C:\Windows\System32\drivers\etc\hosts
浏览器访问,
问题出现了,如果不想折腾,直接关闭防火墙。一步到位!
4 关闭windows 主机的防火墙
可以看到,防火墙已经关闭了
5 再次尝试,浏览器访问
ok 问题解决,撤!
6 总结
在nginx配置无误,就是检查网络环境,两台主机之间通信是否正常(能否相互ping通),如果只能单向: windows主机 ping 通 linux主机,反之不行。直接关闭windows的防火墙,尝试即可。