使用 frp 搭建 https 服务

踩了许多坑,特此记录一下

1、首先服务端的配置(yaml)

复制代码
# 服务端监听本机的 7000 和 443 端口
bindPort: 7000             # 用于 frp 客户端连接
vhostHTTPSPort: 443        # 用于公网的用户访问

# 开启管理后台
webServer:
  addr: "0.0.0.0"          # 可从公网访问
  port: 7005
  user: "admin"
  password: "admin"

2、然后是客户端的配置(yaml)

复制代码
# 服务端的 ip 和端口
serverAddr: "x.x.x.x"
serverPort: 7000

proxies:
  # 开启一个 ssh 服务
  - name: "ssh"
    type: "tcp"
    localIP: "127.0.0.1"
    localPort: 22
    remotePort: 7001

  # 开启一个 web 服务
  - name: "web"
    type: "https"
    #localPort: 80
    customDomains: ["stock.zhuzheng.work"]

    # https 设置
    plugin:
      type: https2http
      localAddr: 127.0.0.1:80

      # https 证书配置
      crtPath: /etc/letsencrypt/live/xxx.com/fullchain.pem
      keyPath: /etc/letsencrypt/live/xxx.com/privkey.pem
      hostHeaderRewrite: 127.0.0.1
      requestHeaders:
        set:
          x-from-where: frp

3、开启阿里云、腾讯云、Amazon AWS、Google GCP 等云服务器的 443 端口

4、使用 certbot 申请 https 证书,参考:https://www.cnblogs.com/isky0824/p/18902686

证书的读取权限很重要,需要正确设置,否则客户端起不来

5、然后开启内网的 http 服务,指定到 80 端口,比如:go 服务、node 服务等。