开发者社区> 问答> 正文

关于访问Nginx中Host请求头中的Host被拦截问题

在阿里云服务器上安装了一个Nginx 做了如下的配置
    location /foo {
        default_type application/json;
        return 200 '{"hello":"world"}';
    }

不指定Host请求头可以正常访问
➜  ~ curl 'http://114.55.176.xxx/foo'
{"hello":"world"}%

随意指定了一个Host请求头 返回如下
➜  ~ curl 'http://114.55.176.xxx/foo' -H 'Host: foo.com'
<html>
<head>
<meta http-equiv="Content-Type" content="textml;charset=UTF-8" />
   <style>body{background-color:#FFFFFF}</style>
<title>TestPage184</title>
  <script language="javascript" type="text/javascript">
         window.onload = function () {
           document.getElementById("mainFrame").src= "http://batit.aliyun.com/alww.html";
            }
</script>
</head>
  <body>
    <iframe style="width:860px; height:500px;position:absolute;margin-left:-430px;margin-top:-250px;top:50%;left:50%;" id="mainFrame" src="" frameborder="0" scrolling="no"></iframe>
    </body>
      </html>

原因是:
主要原因还是指定的host没有在阿里云备案,访问被拦截

那为什么Nginx改成监听81端口后 就不会被拦截了呢?

➜  ~ curl 'http://114.55.176.210:81/foo' -H 'Host: foo.com'
{"hello":"world"}%

以及只不过是Host请求头而已 可以任意指定啊(如httpclient调用第三方接口需要指定某一host请求头 这种情况下你也不能给别人的域名备案啊) 又不是直接访问该域名为什么也要拦截呢?

或者能不能在控制台中取消拦截功能呢?

展开
收起
zhuguowei2 2018-11-02 14:46:56 3998 0
3 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
《Nginx 代理系统常用手册》 立即下载
CentOS Nginx PHP JAVA 多语言镜像使用手 立即下载
CentOS Nginx PHP JAVA多语言镜像使用手册 立即下载