[小技巧] 暂存 - Windows/Linux开机自启配置简记

date
Nov 12, 2023
slug
tip-windows-autostart
status
Published
summary
小技巧
tags
tip
type
Post

Problem & Summary

Solution


# 登陆,并选择授权使用的域名
cloudflared tunnel login
# 创建隧道,此处参数:创建create | 删除delete | 列出list
cloudflared tunnel create argo-sample
# 绑定域名
cloudflared tunnel route dns argo-sample argo-sample.luotianyi.vc
# 临时测试(下发CF提供的临时子域名)
cloudflared tunnel --url localhost:2333
# 正式运行,可参考下文添加运行参数
cloudflared tunnel run --url localhost:2333 argo-sample



--- config.yml:
# Argo隧道的UUID
tunnel: c4c811c0-a514-4f02-9164-0e607d97fb85
# Argo隧道的json路径
credentials-file: C:\cloudflared\c4c811c0-a514-4f02-9164-0e607d97fb85.json

ingress:
  # 设置Argo绑定的域名
  - hostname: argo-sample.luotianyi.vc
    service: http://localhost:8880
  # 默认返回404错误
  - service: http_status:404

# 设置log路径(非必要)
logfile: C:\cloudflared\cloudflared.log



◉ 重载配置:systemctl daemon-reload
◉ 进程管理:service example start|stop|restart
◉ 设置自启:systemctl enable|disable example
--- /etc/systemd/system/example.service
# Argo隧道的UUID
tunnel: c4c811c0-a514-4f02-9164-0e607d97fb85
# Argo隧道的json路径
credentials-file: C:\cloudflared\c4c811c0-a514-4f02-9164-0e607d97fb85.json

ingress:
  # 设置Argo绑定的域名
  - hostname: argo-sample.luotianyi.vc
    service: http://localhost:8880
  # 默认返回404错误
  - service: http_status:404

# 设置log路径(非必要)
logfile: C:\cloudflared\cloudflared.log



--- Windows Service 使用Windows Service配置进程推荐winsw这个项目(点击前往)。首先需要为你要启动的程序写一个xml配置文件比如argo.xml,其中id为进程缩写、name为进程名、description为程序描述、executable为执行exe所在位置、arguments为传递的参数。
--- https://github.com/winsw/winsw

<service>
  <id>argo</id>
  <name>Cloudflare Argo Service</name>
  <description>My Cloudflare Argo Service.</description>
  <executable>C:\cloudflared.exe</executable>
  <arguments>--config=C:\cloudflared\config.yml --protocol http2 tunnel run</arguments>
</service>

Screenshots

notion image

© Ying Bun 2021 - 2025