Nginx - 如何更改请求标头Referer

问题描述 投票:0回答:1

我是 NGINX 新手。 当前使用 NGINX 运行本地反向代理。

只是想知道如何将请求标头中的 Referer 从 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-reverse-proxy
1个回答
3
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.