【问题标题】:Nginx - how to change request header RefererNginx - 如何更改请求标头Referer
【发布时间】:2018-06-27 11:57:26
【问题描述】:

NGINX 新手。 目前正在使用 Nginx 运行本地反向代理。

只是想知道如何将请求标头中的引用者从 http://localhost:8080 更改为不同的 server_name,例如 me.example.com

很难找到有关此主题的明确文档。 已尝试使用以下方法设置此值:

proxy_set_header Referer "me.example.com";

似乎什么也没做。

非常感谢您对此的任何帮助。

server {
  listen       8080;
  server_name  localhost;

   # test APi
  location /test/api {
    # Edit this line only:
    proxy_pass https://test.com/test/api;
    proxy_set_header Host $http_host;

    break;
  }

  location / {
    proxy_pass http://localhost:4567;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-NginX-Proxy true;
    proxy_set_header Referer "me.example.com";
  }
}

【问题讨论】:

  • 你能发布你的nginx配置吗?
  • 添加了 nginx 配置

标签: nginx nginx-reverse-proxy


【解决方案1】:

proxy_set_header 指令将标头发送到后端。如果您希望 nginx 将标头返回给客户端,那么 add_header 指令就是您要寻找的。​​p>

http://nginx.org/en/docs/http/ngx_http_headers_module.html#add_header

【讨论】:

  • 感谢@EstebanGarcia 的回复,尝试添加没有成功:add_header Referer "me.example.com"
  • 将 proxy_set_header Referer "me.example.com" 替换为 add_header Referer "me.example.com"
  • 它将返回一个 json 对象
  • 但是返回的 HTTP 状态码是什么?正如您在我发送给您的文档中看到的那样,add_header 只会在状态码为equals 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0) 时添加标题。还有If the always parameter is specified (1.7.5), the header field will be added regardless of the response code.
  • 返回Referer标头给浏览器是没有意义的,标头只对请求有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多