使用 frp 搭建 https 服务

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

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

# 服务端监听本机的 7000 和 443 端口
bindPort: 7000             # 用于(内网中) frp 客户端的连接
vhostHTTPSPort: 443        # 用于公网中的用户访问

# 开启管理后台
webServer:
  addr: "0.0.0.0"          # 可从公网任意 ip 访问
  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: ["www.xxx.com"]

    # 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 端口)

至此,大功告成!外网的用户可以通过 https://www.xxx.com 访问内网的 web 服务。

posted @ 2025-05-30 14:07  江南烟雨梦  阅读(432)  评论(2)    收藏  举报