gongweixin
V2EX  ›  问与答

遇到了一个神奇的问题

  •  
  •   gongweixin · Mar 21, 2013 · 3535 views
    This topic created in 4825 days ago, the information mentioned may be changed or developed.
    ubuntu 12.04 chromium 在浏览gitcafe.com 显示DNS 查找失败(只有上这个不行,别的都没有问题),因此找不到 gitcafe.com 的服务器 ,果断换了个DNS 依旧无果, 找了个域名 IP查询的网站, 得到gitcafe.com 的ip 为122.226.73.170, 直接输入ip 回车, 结果出现了惊奇的一幕, 地址栏自动变成gitcafe.com了, 然后依旧显示DNS 查找失败 , Why???
    5 replies    1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       Mar 21, 2013   ❤️ 1
    因为 HTTP 服务器检测到你的 host 是这个 IP,它可以将你重定向到以域名来访问,而这个域名你的 DNS 仍然无法解析。

    你要实在搞不定,就改 /etc/hosts 吧。
    gongweixin
        2
    gongweixin  
    OP
       Mar 21, 2013
    @keakon 还是不太理解,host 怎么通过ip重定向到域名的? 怎么知道这个ip就是对应这个域名的? /etc/hosts 怎么怎么改? 已感谢。
    revlis7
        3
    revlis7  
       Mar 21, 2013   ❤️ 1
    应该是gitcafe做了判断,从ip访问自动帮你跳转到域名:

    HTTP/1.1 301 Moved Permanently
    Server: nginx/1.2.4
    Date: Thu, 21 Mar 2013 09:27:07 GMT
    Content-Type: text/html
    Content-Length: 184
    Connection: keep-alive
    Location: https://gitcafe.com/
    keakon
        4
    keakon  
       Mar 21, 2013
    @gongweixin nginx 里可以这样:
    server {
    listen 80;
    server_name 122.226.73.170 gitcafe.com;
    if ($host != 'gitcafe.com') {
    rewrite ^/(.*)$ http://gitcafe.com/$1 permanent;
    }
    }

    /etc/hosts 加一行即可:
    122.226.73.170 gitcafe.com
    gongweixin
        5
    gongweixin  
    OP
       Mar 21, 2013
    @keakon 多谢,成功解决, 再次感谢
    @revlis7 已感谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3028 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 08:42 · PVG 16:42 · LAX 01:42 · JFK 04:42
    ♥ Do have faith in what you're doing.