🌑

帮帮技术站

利用frp自建内网穿透服务

1
2
3
4
做微信支付开发的时候,需要使用到公网回调,希望能够直接访问本地局域网服务。
网上的免费服务不好用,就自己搭建一个了。
参考阿里云文档: https://developer.aliyun.com/article/853534?spm=ding_open_doc.document.0.0.14bc722fy9rQQW

  1. 本地下载frp客户端
1
2
3
下载地址 https://github.com/fatedier/frp/releases/tag/v0.44.0
我这里下载的frp_0.44.0_windows_amd64

服务器端下载frp_0.44.0_linux_amd64

1
2
3
4
wget  https://github.com/fatedier/frp/releases/download/v0.44.0/frp_0.44.0_linux_amd64.tar.gz
tar -xvf frp_0.44.0_linux_amd64.tar.gz
cd frp_0.44.0_linux_amd64

  1. 编辑本地frpc.ini
1
2
3
4
5
6
7
8
9
10
11
12
[common]
server_addr = 82.156.25.146
server_port = 7000
token = jilitoken
vhost_http_port = 7071

[web]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = frp.jiliapp.cn

  • 82.156.25.1 为公网服务器地址
  1. 编辑本地frps.ini
1
2
3
4
5
6
7
8
[common]
bind_port = 7000
vhost_http_port = 7071
token = jilitoken

[web]
type = http
custom_domains = frp.jiliapp.cn
  • custom_domains 域名必须一致。
  1. 启动frps服务端
1
2
3
4
5
6
7

4.1 复制以上第三节的frps.ini覆盖 到服务器端的frps.ini
4.2 启动服务端 ./frps -c ./frps.ini
4.3 确认服务正常后,守护进程启动服务
nohup ./frps -c ./frps.ini >> frps.log 2>&1 &


如下图所示:
启动frps服务端成功

  1. nginx转发配置 frp.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {

listen 80;

server_name frp.jiliapp.cn;

location / {

proxy_pass http://127.0.0.1:7071;

proxy_redirect http://$host/ http://$http_host/;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $host;

}
}

  • 注意: frp.jiliapp.cn的域名解析要解析到公网地址82.156.25.146
  1. 启动本地客户端
1
.\frpc.exe -c .\frpc.ini

启动本地客户端成功

  1. 访问frp.jiliapp.cn域名,会成功返回本地80端口上的index.html

— Feb 2, 2020

Search