[GH-ISSUE #483] host_header_rewrite 有时候代理不到后端 #368

Closed
opened 2026-05-05 12:10:54 -06:00 by gitea-mirror · 11 comments
Owner

Originally created by @tradzero on GitHub (Oct 17, 2017).
Original GitHub issue: https://github.com/fatedier/frp/issues/483

Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly.
(为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。)

Use the commands below to provide key information from your environment:
You do NOT have to include this information if this is a FEATURE REQUEST

What version of frp are you using (./frpc -v or ./frps -v)?
0.13.0

What operating system and processor architecture are you using (go env)?

darwin amd64 macos 10.12.6

Configures you used:

frps.ini

[common]
bind_port = 8080
vhost_http_port = 8081
privilege_token = XXXXX

frpc.ini

[common]
server_addr = XX.XX.XX.XX
server_port = 8080
privilege_token = xxxxxxx

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000

[web]
type = http
local_port = 80
custom_domains = service.domains
host_header_rewrite = client.host

Steps to reproduce the issue:
1.开启frps及frpc
2.访问service.domains:8081
3.访问service.domains:8081/operator

Describe the results you received:
初次访问service.domains:8081时能正确请求host accesslog里host是正确为 client.host 当进入其他链接时 比如service.domains:8081/operator accesslog 显示的host 为service.domains 导致页面全部404
注: service.domains client.host 隐去真实地址

Describe the results you expected:

Additional information you deem important (e.g. issue happens only occasionally):

Can you point out what caused this issue (optional)

Originally created by @tradzero on GitHub (Oct 17, 2017). Original GitHub issue: https://github.com/fatedier/frp/issues/483 Issue is only used for submiting bug report and documents typo. If there are same issues or answers can be found in documents, we will close it directly. (为了节约时间,提高处理问题的效率,不按照格式填写的 issue 将会直接关闭。) Use the commands below to provide key information from your environment: You do NOT have to include this information if this is a FEATURE REQUEST **What version of frp are you using (./frpc -v or ./frps -v)?** 0.13.0 **What operating system and processor architecture are you using (`go env`)?** darwin amd64 macos 10.12.6 **Configures you used:** `frps.ini` ```ini [common] bind_port = 8080 vhost_http_port = 8081 privilege_token = XXXXX ``` `frpc.ini` ```ini [common] server_addr = XX.XX.XX.XX server_port = 8080 privilege_token = xxxxxxx [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 [web] type = http local_port = 80 custom_domains = service.domains host_header_rewrite = client.host ``` **Steps to reproduce the issue:** 1.开启frps及frpc 2.访问service.domains:8081 3.访问service.domains:8081/operator **Describe the results you received:** 初次访问service.domains:8081时能正确请求host accesslog里host是正确为 client.host 当进入其他链接时 比如service.domains:8081/operator accesslog 显示的host 为service.domains 导致页面全部404 注: service.domains client.host 隐去真实地址 **Describe the results you expected:** **Additional information you deem important (e.g. issue happens only occasionally):** **Can you point out what caused this issue (optional)**
gitea-mirror 2026-05-05 12:10:54 -06:00
Author
Owner

@tradzero commented on GitHub (Oct 17, 2017):

另 我的域名是.win 结尾的 不知道有没有影响

<!-- gh-comment-id:337214810 --> @tradzero commented on GitHub (Oct 17, 2017): 另 我的域名是.win 结尾的 不知道有没有影响
Author
Owner

@fatedier commented on GitHub (Oct 19, 2017):

.win 结尾没有影响。

目前 host 替换只对访问链接的第一个 http 请求生效,因为一般 Host 用于做路由,后续同一个连接的不同请求是不需要替换的。我目前的测试还没遇到这个问题。

<!-- gh-comment-id:337842991 --> @fatedier commented on GitHub (Oct 19, 2017): .win 结尾没有影响。 目前 host 替换只对访问链接的第一个 http 请求生效,因为一般 Host 用于做路由,后续同一个连接的不同请求是不需要替换的。我目前的测试还没遇到这个问题。
Author
Owner

@tradzero commented on GitHub (Oct 19, 2017):

@fatedier 对于http来说 请求不是连续的 你刷新 或者进入另外的url时 怎么保证是同一个连接? 如果只有第一个请求更改host 你刷新之后 就穿透到服务器根目录下了呀

<!-- gh-comment-id:337853507 --> @tradzero commented on GitHub (Oct 19, 2017): @fatedier 对于http来说 请求不是连续的 你刷新 或者进入另外的url时 怎么保证是同一个连接? 如果只有第一个请求更改host 你刷新之后 就穿透到服务器根目录下了呀
Author
Owner

@tradzero commented on GitHub (Oct 19, 2017):

@fatedier 可以这样复现 你使用同一个vhosts 然后在index页反复刷新 你就会发现一会是请求到正确到路由上 一会访问的是nginx/apache root下

<!-- gh-comment-id:337853781 --> @tradzero commented on GitHub (Oct 19, 2017): @fatedier 可以这样复现 你使用同一个vhosts 然后在index页反复刷新 你就会发现一会是请求到正确到路由上 一会访问的是nginx/apache root下
Author
Owner

@fatedier commented on GitHub (Oct 19, 2017):

可能表述不清,是对于每一个 TCP 连接的第一个 http 请求。

<!-- gh-comment-id:337862363 --> @fatedier commented on GitHub (Oct 19, 2017): 可能表述不清,是对于每一个 TCP 连接的第一个 http 请求。
Author
Owner

@fatedier commented on GitHub (Oct 19, 2017):

我后端使用 nginx,反复刷新,还是访问其他页面都没有异常。

<!-- gh-comment-id:337863408 --> @fatedier commented on GitHub (Oct 19, 2017): 我后端使用 nginx,反复刷新,还是访问其他页面都没有异常。
Author
Owner

@tradzero commented on GitHub (Oct 19, 2017):

@fatedier 我跟我朋友两个都试过 独立的服务器 独立的客户端 都会出现同样的问题 需要我提供什么来帮助你复现不

<!-- gh-comment-id:337876508 --> @tradzero commented on GitHub (Oct 19, 2017): @fatedier 我跟我朋友两个都试过 独立的服务器 独立的客户端 都会出现同样的问题 需要我提供什么来帮助你复现不
Author
Owner

@fatedier commented on GitHub (Oct 20, 2017):

提供最简化,我可以本地构建环境的 nginx 的配置吧。

<!-- gh-comment-id:338151645 --> @fatedier commented on GitHub (Oct 20, 2017): 提供最简化,我可以本地构建环境的 nginx 的配置吧。
Author
Owner

@tradzero commented on GitHub (Oct 27, 2017):

抱歉这段时间有点忙没办法回复
这是我的vhost配置

   server {
        listen       80;
        server_name  baika.dev;

        root /usr/local/var/www/wc/public;

        location / {
            index  index.php index.html index.htm;
            try_files $uri $uri/ /index.php?$query_string;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }
    }

不过我怀疑这个问题跟nginx本身没有关系 因为我windows端用的是httpd的服务

<!-- gh-comment-id:339852093 --> @tradzero commented on GitHub (Oct 27, 2017): 抱歉这段时间有点忙没办法回复 这是我的vhost配置 ```conf server { listen 80; server_name baika.dev; root /usr/local/var/www/wc/public; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } location ~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } ``` 不过我怀疑这个问题跟nginx本身没有关系 因为我windows端用的是httpd的服务
Author
Owner

@fatedier commented on GitHub (Oct 27, 2017):

我需要的就是能够稳定复现的环境,可以方便调试,或者你可以自己抓包分析一下,报文转发后哪里存在问题。

<!-- gh-comment-id:339878778 --> @fatedier commented on GitHub (Oct 27, 2017): 我需要的就是能够稳定复现的环境,可以方便调试,或者你可以自己抓包分析一下,报文转发后哪里存在问题。
Author
Owner

@fatedier commented on GitHub (Jan 17, 2018):

可以用 0.14.1 版本测试下。

<!-- gh-comment-id:358359107 --> @fatedier commented on GitHub (Jan 17, 2018): 可以用 0.14.1 版本测试下。
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/frp#368
No description provided.