frp内网穿透

搭建自己的网盘一直苦于内网穿透,好在VPS有个公网IP

系统和vps规则中都要设置打开相应端口

frps.ini配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 下面这句开头必须要有,表示配置的开始
[common]
# frps 服务端端口(必须)
bind_port = 7000

# 如果你想要用 frp 穿透访问内网中的网站(例如路由器设置页面)
# 则必须要设置以下两个监听端口,不设置则不会开启这项功能
vhost_http_port = 10080
vhost_https_port = 10443

# frp 服务端密码(必须)
token = 12345678
subdomain_host = example.com

frpc.ini配置

1
2
3
4
5
6
7
8
9
10
11
12
[common]
# 远程端IP
server_addr = 0.0.0.0
server_port = 7000
# 与frps密码要一致
token = p2340817

[web_ssh]
type = http
local_ip = 192.168.1.122
local_port = 80
custom_domain = frp.nextcloud.com

启动:

1
$ ./frpc -c ./frpc.ini

服务端开机启动:

sudo vim /etc/systemd/system/frps.service

1
2
3
4
5
6
7
8
9
10
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
ExecStart=/usr/bin/frps -c /etc/frps/frps.ini

[Install]
WantedBy=multi-user.target

sudo systemctl enable frps

sudo systemctl start frps

nextcloud添加信任IP或域名:(路径可能有所差异,自行用find / -name config.php查找)

1
$ vim /var/www/html/nextcloud/config/config.php

给客户端分配固定IP:

以ubuntu20.04LTS为例

sudo vim /etc/netplan/00-installer-config.yaml

1
2
3
4
5
6
7
8
9
10
11
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.4.59/24
gateway4: 192.168.4.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]

然后让配置生效

sudo netplan apply

参考链接:

https://www.shangyexin.com/2020/01/20/frp/