This page looks best with JavaScript enabled

Publishing Local Services to the Public Network with frp

 ·  ☕ 2 min read

1. What frp Is

frp is a high-performance reverse proxy application. It provides:

  • Using a machine behind a private network or firewall to expose http or https services to the external network
  • For http and https services, it supports domain-based virtual hosts and custom domain binding, so multiple domains can share a single port 80
  • Using a machine behind a private network or firewall to expose tcp and udp services to the external network, for example reaching a host on your company’s private network from home over ssh

2. Architecture and Deployment

frp uses a C/S architecture. To use it, you need to:

  1. Deploy the server: put frps and frps.ini on a machine with a public IP and run frps;

  2. Deploy the client: put frpc and frpc.ini on a machine inside the private network and run frpc.

frp is written in Go and supports OS X, Windows, and Linux.

3. Installing frp on the Server

There are two ways to install frp on the server.

  • Download a Releases build from GitHub and install it manually
  • Install with the script written by clangcn

The steps below use the script installation:

  • Download the script
1
wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh
  • Add execute permission
1
chmod +x install-frps.sh
  • Run the installation
1
./install-frps.sh install

During installation you need to fill in some configuration parameters:

 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
27
Please input frps bind_port [1-65535](Default Server Port: 5443):
输入frp提供服务的端口,用于服务器端和客户端通信,按Enter键表示默认5443,否则手动输入新端口
Please input frps dashboard_port [1-65535](Default dashboard_port: 6443):
输入frp的控制台服务端口,用于查看frp工作状态,按Enter键表示默认6443,否则手动输入新端口
Please input frps vhost_http_port [1-65535](Default vhost_http_port: 80):
输入frp进行http穿透的http服务端口,按Enter键表示默认80,否则手动输入新端口,一般不建议默认80
Please input frps vhost_https_port [1-65535](Default vhost_https_port: 443):
输入frp进行https穿透的https服务端口,按Enter键表示默认443,否则手动输入新端口
Please input privilege_token (Default: XXXXXXXXXXXXXXXXX):
输入frp服务器和客户端通信的密码,默认是随机生成的,按Enter键表示按默认来,否则手动输入。frpc客户端需要这个接头暗号
Please input frps max_pool_count [1-200](Default max_pool_count: 50):
设置每个代理可以创建的连接池上限,默认50
Please select log_level #####
    1: info
    2: warn
    3: error
    4: debug
Enter your choice (1, 2, 3, 4 or exit. default [1]):
设置日志等级,4个选项,默认是info
Please input frps log_max_days [1-30]
    (Default log_max_days: 3 day):
设置日志保留天数,范围是1到30天,默认保留3天。
##### Please select log_file #####
    1: enable
    2: disable
Enter your choice (1, 2 or exit. default [1]):
设置是否开启日志记录,默认开启,开启后日志等级及保留天数生效,否则等级和保留天数无效

4. Client Configuration

On the frp releases page you can find a package that fits Windows. After downloading it, edit the configuration file frpc.ini:

1
2
3
4
5
6
7
8
9
[common]
server_addr = 111.222.333.444
server_port = 5443
token = XXXXXXXX

[web]
type = http
local_port = 8000
custom_domains = xxx.chenshaowen.com

Parameter description:

  • server_addr, the IP address of the server
  • server_port, the port bound on the server
  • token, the token for the frp service

The local project is a Django project, with the service bound to port 8000.

At the same time, in DNS you need to point xxx.chenshaowen.com at 111.222.333.444 (the address of the frp server)

Run the local client:

1
./frpc -c ./frpc.ini

At this point you can access the local service directly through the public domain:

5. Router Configuration

In the KoolShare software center, install the [Virtual Memory] and [frpc Traversal] plugins.

Configure the server-side information (after the script installation of the frp server succeeds, it prints the complete configuration information)

Configure port mapping to forward external access to the specified internal port:

Finally, do not forget to resolve the domain in [Domain Configuration/SK] to the frp server address.

6. References


WeChat Official Account
WRITTEN BY
WeChat Official Account