下载对应平台的frp客户端或者服务端

https://github.com/fatedier/frp/releases

创建frp的docker镜像

frpc的Dockerfile

FROM alpine:3.14

MAINTAINER bob 115765728@qq.com

RUN apk add --no-cache -U tzdata

RUN echo "Asia/shanghai" >> /etc/timezone

RUN echo export LANG=zh_CN.utf8 > /etc/profile.d/locale.sh

#设置语言
ENV LANG=zh_CN.UTF-8 \
    LANGUAGE=zh_CN.UTF-8
ENV TZ=Asia/Shanghai

RUN mkdir /app
COPY frpc.ini /app
COPY frpc /
RUN chmod 0755 /frpc

EXPOSE 7000

ENTRYPOINT ["/frpc","-c","/app/frpc.ini"]

frpc.ini

[common]
#server_addr = 127.0.0.1
#server_port = 7000

[ssh]
#type = tcp
#local_ip = 127.0.0.1
#local_port = 22
#remote_port = 6000

frps的Dockerfile

FROM alpine:3.14

MAINTAINER bob 115765728@qq.com

RUN apk add --no-cache -U tzdata

RUN echo "Asia/shanghai" >> /etc/timezone

RUN echo export LANG=zh_CN.utf8 > /etc/profile.d/locale.sh

#设置语言
ENV LANG=zh_CN.UTF-8 \
    LANGUAGE=zh_CN.UTF-8
ENV TZ=Asia/Shanghai

RUN mkdir /app
COPY frps.ini /app
COPY frps /
RUN chmod 0755 /frps

EXPOSE 7000

ENTRYPOINT ["/frps","-c","/app/frps.ini"]

frps.ini

# [common] is integral section
[common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
# For single "bind_addr" field, no need square brackets, like "bind_addr = ::".
bind_addr = 0.0.0.0
bind_port = 7000

# udp port to help make udp hole to penetrate nat
bind_udp_port = 7001

# udp port used for kcp protocol, it can be same with 'bind_port'
# if not set, kcp is disabled in frps
kcp_bind_port = 7000

# specify which address proxy will listen for, default value is same with bind_addr
# proxy_bind_addr = 127.0.0.1

# if you want to support virtual host, you must set the http port for listening (optional)
# Note: http port and https port can be same with bind_port
vhost_http_port = 80
vhost_https_port = 443

# response header timeout(seconds) for vhost http server, default is 60s
# vhost_http_timeout = 60

# tcpmux_httpconnect_port specifies the port that the server listens for TCP
# HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
# requests on one single port. If it's not - it will listen on this value for
# HTTP CONNECT requests. By default, this value is 0.
# tcpmux_httpconnect_port = 1337

# set dashboard_addr and dashboard_port to view dashboard of frps
# dashboard_addr's default value is same with bind_addr
# dashboard is available only if dashboard_port is set
dashboard_addr = 0.0.0.0
dashboard_port = 7500

# dashboard user and passwd for basic auth protect
dashboard_user = admin
dashboard_pwd = admin

# enable_prometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port} in /metrics api.
enable_prometheus = true

# dashboard assets directory(only for debug mode)
# assets_dir = ./static

# console or real logFile path like ./frps.log
#log_file = /opt/frps/frps.log

# trace, debug, info, warn, error
log_level = info

log_max_days = 3

# disable log colors when log_file is console, default is false
disable_log_color = false

# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
detailed_errors_to_client = true

# authentication_method specifies what authentication method to use authenticate frpc with frps.
# If "token" is specified - token will be read into login message.
# If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token".
authentication_method = token

# authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
authenticate_heartbeats = false

# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
authenticate_new_work_conns = false

# auth token
token = 123456

# if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file
# when subdomain is test, the host used by routing is test.frps.com
subdomain_host = baidu.com

为frp进行域名解析设置

frp进行http映射需要设置域名;
第一步配置域名:
以自己的腾讯云为例,添加第一条解析记录
20180515145509341.jpg

主机记录处填写frp
记录值处填写vps的外网IP

添加第二条解析记录
20180515145929245.jpg

主机记录处填写*.frp
记录值处填写frp.+域名

第二步配置frps.ini和frpc.ini

# [common] is integral section
[common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
# For single "bind_addr" field, no need square brackets, like "bind_addr = ::".
bind_addr = 0.0.0.0
bind_port = 7000

# udp port to help make udp hole to penetrate nat
bind_udp_port = 7001

# udp port used for kcp protocol, it can be same with 'bind_port'
# if not set, kcp is disabled in frps
kcp_bind_port = 7000

# specify which address proxy will listen for, default value is same with bind_addr
# proxy_bind_addr = 127.0.0.1

# if you want to support virtual host, you must set the http port for listening (optional)
# Note: http port and https port can be same with bind_port
vhost_http_port = 80
#vhost_https_port = 443

# response header timeout(seconds) for vhost http server, default is 60s
# vhost_http_timeout = 60

# tcpmux_httpconnect_port specifies the port that the server listens for TCP
# HTTP CONNECT requests. If the value is 0, the server will not multiplex TCP
# requests on one single port. If it's not - it will listen on this value for
# HTTP CONNECT requests. By default, this value is 0.
# tcpmux_httpconnect_port = 1337

# set dashboard_addr and dashboard_port to view dashboard of frps
# dashboard_addr's default value is same with bind_addr
# dashboard is available only if dashboard_port is set
dashboard_addr = 0.0.0.0
dashboard_port = 7500

# dashboard user and passwd for basic auth protect
dashboard_user = admin
dashboard_pwd = admin

# enable_prometheus will export prometheus metrics on {dashboard_addr}:{dashboard_port} in /metrics api.
enable_prometheus = true

# dashboard assets directory(only for debug mode)
# assets_dir = ./static

# console or real logFile path like ./frps.log
#log_file = /app/frps.log

# trace, debug, info, warn, error
log_level = info

log_max_days = 3

# disable log colors when log_file is console, default is false
disable_log_color = false

# DetailedErrorsToClient defines whether to send the specific error (with debug info) to frpc. By default, this value is true.
detailed_errors_to_client = true

# authentication_method specifies what authentication method to use authenticate frpc with frps.
# If "token" is specified - token will be read into login message.
# If "oidc" is specified - OIDC (Open ID Connect) token will be issued using OIDC settings. By default, this value is "token".
authentication_method = token

# authenticate_heartbeats specifies whether to include authentication token in heartbeats sent to frps. By default, this value is false.
authenticate_heartbeats = false

# AuthenticateNewWorkConns specifies whether to include authentication token in new work connections sent to frps. By default, this value is false.
authenticate_new_work_conns = false

# auth token
token = 123456

# if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file
# when subdomain is test, the host used by routing is test.frps.com
subdomain_host = diynet.top

# if tcp stream multiplexing is used, default is true
#tcp_mux = true

# specify keep alive interval for tcp mux.
# only valid if tcp_mux is true.
# tcp_mux_keepalive_interval = 60

# specify udp packet size, unit is byte. If not set, the default value is 1500.
# This parameter should be same between client and server.
# It affects the udp and sudp proxy.
#udp_packet_size = 1500
[common]
server_addr = diynet.top
server_port = 7000
token = 123456

# 注意下面的yourname要取一个和别人不重复的名字,名称冲突会启动失败

# http示例
[http]
type = http
local_ip = 172.17.0.11
local_port = 80
# 自己的域名
custom_domains = diynet.top
# 子域名(不要和别人重复)
#subdomain = zfile

[ssh]
type = tcp
local_ip = 192.168.5.134 为本机的ip地址
local_port = 3389
remote_port =6600

运行frp的docker容器

docker run -itd --name=frps --restart=always -p 80:80/tcp -p 443:443/tcp -p 7000:7000/tcp -p 7000:7000/udp -p 7001:7001/udp -p 7500:7500/tcp -v /mnt/appdata/frps:/app bob/frps:v1
docker run -itd --name=frpc --restart=always -v /mnt/appdata/frpc:/app bob/frpc:v1
文章目录