修改 HTTP 请求 Header

修改 Host Header

通常情况下 frp 不会修改转发的任何数据。但有一些后端服务会根据 HTTP 请求 header 中的 Host 字段来展现不同的网站,例如 nginx 的虚拟主机服务,启用 Host Header 的修改功能可以动态修改 HTTP 请求中的 Host 字段。需要注意的是,该功能仅限于 HTTP 类型的代理。

# frpc.toml
    [[proxies]]
    name = "web"
    type = "http"
    localPort = 80
    customDomains = ["test.yourdomain.com"]
    hostHeaderRewrite = "dev.yourdomain.com"
    

原来 HTTP 请求中的 Host 字段 test.yourdomain.com 转发到后端服务时会被替换为 dev.yourdomain.com

设置普通 Header

对于类型为 HTTP 的代理,可以设置在转发中动态添加的 Header 参数

# frpc.toml
    [[proxies]]
    name = "web"
    type = "http"
    localPort = 80
    customDomains = ["test.yourdomain.com"]
    hostHeaderRewrite = "dev.yourdomain.com"
    requestHeaders.set.x-from-where = "frp"
    

根据如上的配置,会在请求的 Header 中加上 x-from-where: frp

最后修改 November 15, 2023: fix 404 (#71) (626ce4d)

Modify HTTP request Header

Modify Host header

Usually, FRP does not modify any forwarded data. But some backend services will be based on The Host field in the HTTP request header is used to display different websites, such as nginx The virtual host service enables the modification function of the Host Header to dynamically modify HTTP The Host field in the request. It should be noted that this feature is limited to HTTP only Type of Agent.

# frpc.toml
    [[proxies]]
    name = "web"
    type = "http"
    localPort = 80
    customDomains = ["test.yourdomain.com"]
    hostHeaderRewrite = "dev.yourdomain.com"
    

The Host field in the original HTTP request When forwarding to the backend service, it will be replaced with Dev. yourdomain. com.

Set Normal Header

For agents of type HTTP, the header dynamically added in forwarding can be set parameter

# frpc.toml
    [[proxies]]
    name = "web"
    type = "http"
    localPort = 80
    customDomains = ["test.yourdomain.com"]
    hostHeaderRewrite = "dev.yourdomain.com"
    requestHeaders.set.x-from-where = "frp"
    

According to the above configuration, it will be added to the header of the request x-from-where: frp

Last modified November 15, 2023: fix 404 (#71) (626ce4d)