[GH-ISSUE #3912] 请教一下使用Nginx作为frps前置反向代理的配置 #3100

Closed
opened 2026-05-05 14:00:33 -06:00 by gitea-mirror · 5 comments
Owner

Originally created by @Fiary-Tale on GitHub (Jan 5, 2024).
Original GitHub issue: https://github.com/fatedier/frp/issues/3912

Bug Description

Bug Description
当我配置完代理后,我去访问我配置的58880端口时,会发现跳转到frp错误页面
image
frps日志错误为:2024/01/06 06:39:08 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost /
我记得老的版本可以这样访问,因为我要做nginx反向代理,同时要将通过IP访问进行禁用,只允许通过域名进行访问。

frpc Version

0.53.2

frps Version

0.53.2

System Architecture

linux/adm64

Configurations

我的frps.toml配置是
image
我的frpc.toml配置是
image

Logs

2024/01/06 06:09:34 [W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 /
2024/01/06 06:09:50 [W] [http.go:119] do http proxy request [host: 10.0.8.10:58880] error: no route found: 10.0.8.10 /
2024/01/06 06:09:53 [W] [http.go:119] do http proxy request [host: 10.0.8.10:58880] error: no route found: 10.0.8.10 /
2024/01/06 06:10:01 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost /
2024/01/06 06:39:08 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost /

Steps to reproduce

...

Affected area

  • Docs
  • Installation
  • Performance and Scalability
  • Security
  • User Experience
  • Test and Release
  • Developer Infrastructure
  • Client Plugin
  • Server Plugin
  • Extensions
  • Others
Originally created by @Fiary-Tale on GitHub (Jan 5, 2024). Original GitHub issue: https://github.com/fatedier/frp/issues/3912 ### Bug Description Bug Description 当我配置完代理后,我去访问我配置的58880端口时,会发现跳转到frp错误页面 ![image](https://github.com/fatedier/frp/assets/87681228/1a53c7a2-ac75-4d78-a481-478011727837) frps日志错误为:2024/01/06 06:39:08 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost / 我记得老的版本可以这样访问,因为我要做nginx反向代理,同时要将通过IP访问进行禁用,只允许通过域名进行访问。 ### frpc Version 0.53.2 ### frps Version 0.53.2 ### System Architecture linux/adm64 ### Configurations 我的frps.toml配置是 ![image](https://github.com/fatedier/frp/assets/87681228/f329ee27-9078-44a6-9b8e-fb31f3027b0c) 我的frpc.toml配置是 ![image](https://github.com/fatedier/frp/assets/87681228/2fc1fb2d-7b1a-4489-b354-182850d399b7) ### Logs 2024/01/06 06:09:34 [W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 / 2024/01/06 06:09:50 [W] [http.go:119] do http proxy request [host: 10.0.8.10:58880] error: no route found: 10.0.8.10 / 2024/01/06 06:09:53 [W] [http.go:119] do http proxy request [host: 10.0.8.10:58880] error: no route found: 10.0.8.10 / 2024/01/06 06:10:01 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost / 2024/01/06 06:39:08 [W] [http.go:119] do http proxy request [host: localhost:58880] error: no route found: localhost / ### Steps to reproduce 1. 2. 3. ... ### Affected area - [ ] Docs - [ ] Installation - [ ] Performance and Scalability - [ ] Security - [ ] User Experience - [ ] Test and Release - [ ] Developer Infrastructure - [ ] Client Plugin - [ ] Server Plugin - [ ] Extensions - [ ] Others
Author
Owner

@superzjg commented on GitHub (Jan 6, 2024):

先弄清楚 localAddrlocalIP的使用场景

<!-- gh-comment-id:1879530571 --> @superzjg commented on GitHub (Jan 6, 2024): 先弄清楚 `localAddr` 与 `localIP`的使用场景
Author
Owner

@Fiary-Tale commented on GitHub (Jan 6, 2024):

首先,非常感谢您的回复,为我解答疑惑,其次抱歉,我在文档中,并没有找到localAddr的使用案例,也没有找到讲解方法,但是我不使用localAddrlocalIP时,在客户端设置remotePort = 58880,服务端设置vhostHTTPPort = 58880时,我使用curl http://127.0.0.1:58880,一样会产生错误,导致我无法使用nginx反向代理设置。错误如下图
访问http://127.0.0.1:58880
image
frps配置
`bindAddr = "0.0.0.0"
bindPort = 60001
vhostHTTPPort = 58880
log.to = "console"

auth.method = "token"
auth.token = "xxxxxxxxxxx"
`

frpc配置

`serverAddr = "1.1.1.1" # 这里我写的是真实ip,1.1.1.1只是临时填写
serverPort = 60001
auth.method = "token"
auth.token = "xxxxxxxxxxx"

proxies
name = "lskyweb"
type = "http"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 58880
customDomains = ["1.1.1.1"] # 这里我写的是真实ip,1.1.1.1只是临时填写
`

frps错误日志

[W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 /

此时如果我的vps开放了58880端口,使用curl http://x.x.x.x:58880这个时候是可以正常访问的,唯独访问localhost、127.0.0.1或内网ip的58880端口无法访问

<!-- gh-comment-id:1879693340 --> @Fiary-Tale commented on GitHub (Jan 6, 2024): 首先,非常感谢您的回复,为我解答疑惑,其次抱歉,我在文档中,并没有找到`localAddr`的使用案例,也没有找到讲解方法,但是我不使用`localAddr`或`localIP`时,在客户端设置`remotePort = 58880`,服务端设置`vhostHTTPPort = 58880`时,我使用`curl http://127.0.0.1:58880`,一样会产生错误,导致我无法使用nginx反向代理设置。错误如下图 访问http://127.0.0.1:58880 ![image](https://github.com/fatedier/frp/assets/87681228/6ad5b4a2-232d-4bcf-b9cd-328474b65f47) frps配置 `bindAddr = "0.0.0.0" bindPort = 60001 vhostHTTPPort = 58880 log.to = "console" auth.method = "token" auth.token = "xxxxxxxxxxx" ` frpc配置 `serverAddr = "1.1.1.1" # 这里我写的是真实ip,1.1.1.1只是临时填写 serverPort = 60001 auth.method = "token" auth.token = "xxxxxxxxxxx" [[proxies]] name = "lskyweb" type = "http" localIP = "127.0.0.1" localPort = 8080 remotePort = 58880 customDomains = ["1.1.1.1"] # 这里我写的是真实ip,1.1.1.1只是临时填写 ` frps错误日志 `[W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 /` 此时如果我的vps开放了58880端口,使用`curl http://x.x.x.x:58880`这个时候是可以正常访问的,唯独访问localhost、127.0.0.1或内网ip的58880端口无法访问
Author
Owner

@Fiary-Tale commented on GitHub (Jan 6, 2024):

我看到,您在其他nginx反向代理的issue中提到要先添加localIP,那么我添加localIP后,配置如下:

`serverAddr = "1.1.1.1"
serverPort = 60001
auth.method = "token"
auth.token = "xxxxxxx"

proxies
name = "lskyweb"
type = "http"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 58880
customDomains = ["1.1.1.1"]
`

但是依旧会无法访问localhost、127.0.0.1或内网ip的58880端口,但是可以通过公网ip进行访问,我在公网服务器的shell中
访问错误如下:
image
2024/01/06 22:09:16 [W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 /

<!-- gh-comment-id:1879698378 --> @Fiary-Tale commented on GitHub (Jan 6, 2024): 我看到,您在其他nginx反向代理的issue中提到要先添加`localIP`,那么我添加`localIP`后,配置如下: `serverAddr = "1.1.1.1" serverPort = 60001 auth.method = "token" auth.token = "xxxxxxx" [[proxies]] name = "lskyweb" type = "http" localIP = "127.0.0.1" localPort = 8080 remotePort = 58880 customDomains = ["1.1.1.1"] ` 但是依旧会无法访问localhost、127.0.0.1或内网ip的58880端口,但是可以通过公网ip进行访问,我在公网服务器的shell中 访问错误如下: ![image](https://github.com/fatedier/frp/assets/87681228/2050f673-6436-43e5-a360-848bc8661c64) 2024/01/06 22:09:16 [W] [http.go:119] do http proxy request [host: 127.0.0.1:58880] error: no route found: 127.0.0.1 /
Author
Owner

@Fiary-Tale commented on GitHub (Jan 6, 2024):

已经搞明白如何进行反向代理的设置了,需要把customDomains = ["1.1.1.1"]这个配置为customDomains = ["127.0.0.1"],就会默认转发到他的127.0.0.1:58880端口上,这样就可以做nginx反向代理了

<!-- gh-comment-id:1879724471 --> @Fiary-Tale commented on GitHub (Jan 6, 2024): 已经搞明白如何进行反向代理的设置了,需要把customDomains = ["1.1.1.1"]这个配置为customDomains = ["127.0.0.1"],就会默认转发到他的127.0.0.1:58880端口上,这样就可以做nginx反向代理了
Author
Owner

@Lioncky commented on GitHub (May 3, 2025):

我遇到的问题更诡异 ngix反代直接挂掉 我还以为frps出问题了 结果正常走127.0.0.1:RemotePort可以正常访问 重启了下服务器ok了 反代要设置Proxy_host 也就是 127.0.0.1 这个还没文档的差评

ngix 反代设置 不需要用frps的v1 v2 ngix直接可以拿到X-Real-IP

#PROXY-START/

location ^~ /
{
    proxy_pass http://127.0.0.1:880;
    proxy_set_header Host $proxy_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;

    #Persistent connection related configuration

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache
    
    
    set $static_filemi146aOz 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
    	set $static_filemi146aOz 1;
    	expires 12h;
        }
    if ( $static_filemi146aOz = 0 )
    {
    add_header Cache-Control no-cache;
    }
}

#PROXY-END/
<!-- gh-comment-id:2848539182 --> @Lioncky commented on GitHub (May 3, 2025): 我遇到的问题更诡异 ngix反代直接挂掉 我还以为frps出问题了 结果正常走127.0.0.1:RemotePort可以正常访问 重启了下服务器ok了 反代要设置Proxy_host 也就是 127.0.0.1 这个还没文档的差评 ngix 反代设置 不需要用frps的v1 v2 ngix直接可以拿到X-Real-IP ``` #PROXY-START/ location ^~ / { proxy_pass http://127.0.0.1:880; proxy_set_header Host $proxy_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header REMOTE-HOST $remote_addr; #Persistent connection related configuration add_header X-Cache $upstream_cache_status; #Set Nginx Cache set $static_filemi146aOz 0; if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" ) { set $static_filemi146aOz 1; expires 12h; } if ( $static_filemi146aOz = 0 ) { add_header Cache-Control no-cache; } } #PROXY-END/ ```
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#3100
No description provided.