通过frp设置https访问,一种是前置nginx,在nginx上设置证书,然后nginx再转发到frp代理的http/https服务。

另外可以通过frp直接设置证书进行https访问。

在搭建drone服务的时候,遇到了这个问题:想要通过https访问drone,且通过frp直接访问,没有使用nginx之类工具。而且,使用的是ip。

正常一般这样配置,然后通过远程服务器的ip+端口9531即可访问:

serverAddr = "x.x.x.x"
serverPort = 7000
auth.token = "xxxxxxx"
[[proxies]]
name = "drone"
type = "tcp"
remotePort = 9531
localIP = "127.0.0.1"
localPort = 7070

而文档写的https访问又是通过域名的,类型选择为https:

serverAddr = "x.x.x.x"
serverPort = 7000

[[proxies]]
name = "test_htts2http"
type = "https"
customDomains = ["test.yourdomain.com"]

[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:80"

# HTTPS 证书相关的配置
crtPath = "./server.crt"
keyPath = "./server.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

如果选择了 type = ”https” 就没办法设置远程的端口,实际上类型设置为 tcp 也是可以的,然后配置证书相关的信息:

serverAddr = "x.x.x.x"
serverPort = 7000
auth.token = "xxxxxxx"

[[proxies]]
name = "drone"
type = "tcp"
remotePort = 7005

[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:7070"
# HTTPS 证书相关的配置
crtPath = "cer.crt"
keyPath = "private.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

此时即可通过 https://x.x.x.x:7005 访问

drone的配置,需要注意runner设置DRONE_RPC_HOST的地址为https地址

services:

  server:
    image: drone/drone
    ports:
    - 7070:80
    - 7071:443
    volumes:
    - /opt/drone/data:/data:rw
    networks:
    - drone
    restart: always
    environment:
    # 你的服务器域名或ip
    - DRONE_SERVER_HOST=x.x.x.x:7005
    # 使用的协议http或者https
    - DRONE_SERVER_PROTO=https
    # runner通信密钥,后面runner也要配置相同的值
    - DRONE_RPC_SECRET=xxxxx
    # gitee第三方应用client id
    - DRONE_GITEE_CLIENT_ID=xxxxx
    # gitee第三方应用client secret
    - DRONE_GITEE_CLIENT_SECRET=xxxxx
    # 默认创建账户,设置你的gitee用户名,这样你登录后是作为管理员
    - DRONE_USER_CREATE=username:xxx,admin:true

  runner:
    image: drone/drone-runner-docker
    restart: always
    ports:
    - 3000:3000
    networks:
    - drone
    depends_on:
    - server
    volumes:
    # 挂载宿主机的docker sock,runner实际还是使用的宿主机的docker daemon
    - /var/run/docker.sock:/var/run/docker.sock:rw
    environment:
    # 与drone server通信的协议http/https
    - DRONE_RPC_PROTO=https
    # drone server服务器
    - DRONE_RPC_HOST=x.x.x.x:7005
    # drone server rpc密钥
    - DRONE_RPC_SECRET=xxxxx
    # runner name,标识runner
    - DRONE_RUNNER_NAME=runner
    # runner最多同时执行任务数
    - DRONE_RUNNER_CAPACITY=2
    # runner使用协议http/https
    - DRONE_HTTP_PROTO=http
    # runner的host,server向runner主动推送任务时使用此配置,如果在不同服务器此处应该设置为runner的域名或ip,此处是同一服务器,所以使用docker service name是可以直接访问的
    - DRONE_HTTP_HOST=runner

networks:
  drone: