檢查步驟如下:
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的防火墻,嘗試即可。