【问题标题】:nginx reverse-proxy rewriting custom header (NOT URL)nginx反向代理重写自定义标头(不是URL)
【发布时间】:2021-09-10 16:26:34
【问题描述】:

我正在尝试使用 nginx 反向代理重写自定义标头信息,例如“作者”(不是 URL 的一部分)。 标题信息“作者:”应从“test123”重写为例如“基本”

命令:

admin1@nginx1:~$curl -x 192.168.175.134:80 http://home1.MyWeb.eu:8081/home1/index.html?t=1 -H "Author: test123" -vk

Apache 上的 TCPdump:

--
GET /home1/index.html?t=1 HTTP/1.0
Host: home1.MyWeb.eu
Connection: close
User-Agent: curl/7.58.0
Accept: */*
Proxy-Connection: Keep-Alive
Author: test123

想要的结果:

--
GET /home1/index.html?t=1 HTTP/1.0
Host: home1.MyWeb.eu
Connection: close
User-Agent: curl/7.58.0
Accept: */*
Proxy-Connection: Keep-Alive
Author: BASIC

【问题讨论】:

    标签: nginx url-rewriting http-headers reverse-proxy


    【解决方案1】:

    您可以在配置中使用proxy_set_header。即:

    proxy_set_header            Author        "BASIC";
    

    【讨论】:

    • 感谢您的回答,但不幸的是,我需要根据实际标头值更改标头信息。如果标题为“test123”,我需要将其更改为 BASIC,如果标题值为“TEST789”,我需要更改为例如“先进的”。我曾尝试使用 REGEX,但没有成功。
    猜你喜欢
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-23
    • 2019-03-12
    • 2018-03-06
    • 2020-12-18
    • 2020-05-31
    • 2019-11-04
    相关资源
    最近更新 更多