frp内网穿透详解(linux)

1、下载frp,frp_0.37.1_linux_amd64.tar.gz

2、将文件传至服务器/root目录(不改了)

1
2
tar zxvf frp_0.37.1_linux_amd64.tar.gz
mv frp_0.37.1_linux_amd64.tar.gz frp

3、修改frps.ini

1
2
3
4
5
6
7
8
9
10
11
[common]
bind_port = 7000
token = hmlove.online
# nginx and frp
vhost_http_port = 7080

dashboard_port = 7500
dashboard_user = xxx
dashboard_pwd = xxx

subdomain_host = xxx

4、添加自启动服务

1
vim /lib/systemd/system/frps.service

在frps.service里写入以下内容

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=frps service
After=network.target syslog.target
Wants=network.target

[Service]
Type=simple
ExecStart=/root/frp/frps -c /root/frp/frps.ini

[Install]
WantedBy=multi-user.target
1
2
3
systemctl start frps   # 启动frps

sudo systemctl enable frps # 打开自启动

如果要重启应用,可以这样,systemctl restart frps
如果要停止应用,可以输入,systemctl stop frps
如果要查看应用的日志,可以输入,systemctl status frps

5、编辑frp.conf,丢到nginx的vhost目录中,并重载nginx配置 :/www/server/nginx/sbin/nginx -s reload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
server {
listen 80;
server_name yzht.ltd;

location / {
proxy_pass http://127.0.0.1:7500;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
}

# proxy http web
server {
listen 80;
server_name *.yzht.ltd;

location / {
proxy_pass http://127.0.0.1:7080;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_hide_header X-Powered-By;
}
}

开放端口7000,7080,7500。

至此,服务器端工作完成

6、登录云控制平台,在防火墙或安全组中,再次打开以上三个端口。

7、云平台的域名解析中加入需要内网穿透的域名解析。

8、配置内网主机的穿透文件,可以用docker来完成多个主机的解析。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frpc.ini
[common]
server_addr = IP
server_port = 7000
token = token

[dsm]
type = tcp
local_ip = 192.168.66.130
local_port = 5001
remote_port = 5001

[bbs]
type = http
local_ip = 192.168.66.121
local_port = 80
subdomain = bbs

[lede]
type = http
local_ip = 192.168.66.22
local_port = 80
subdomain = lede