安装CADDY
curl https://getcaddy.com | bash -s personal net
配置CADDY服务
/etc/systemd/system/caddy.service
[Unit] Description=Caddy HTTP/2 web server Documentation=https://caddyserver.com/docs After=network-online.target Wants=network-online.target systemd-networkd-wait-online.service [Service] Restart=on-abnormal ; Always set "-root" to something safe in case it gets forgotten in the Caddyfile. ExecStart=/usr/local/bin/caddy -conf=/etc/caddy/Caddyfile ExecReload=/bin/kill -USR1 $MAINPID ; Use graceful shutdown with a reasonable timeout KillMode=mixed KillSignal=SIGQUIT TimeoutStopSec=5s ; Limit the number of file descriptors; see `man systemd.exec` for more limit settings. LimitNOFILE=1048576 ; Unmodified caddy is not expected to use more than that. LimitNPROC=512 ; Use private /tmp and /var/tmp, which are discarded after caddy stops. PrivateTmp=true ; Use a minimal /dev PrivateDevices=true ; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. ProtectHome=true ; Make /usr, /boot, /etc and possibly some more folders read-only. ProtectSystem=full [Install] WantedBy=multi-user.target
/etc/systemd/system/caddytcp.service
[Unit] Description=Caddy HTTP/2 web server Documentation=https://caddyserver.com/docs After=network-online.target Wants=network-online.target systemd-networkd-wait-online.service [Service] Restart=on-abnormal ; Always set "-root" to something safe in case it gets forgotten in the Caddyfile. ExecStart=/usr/local/bin/caddy -type=net -conf=/etc/caddy/CaddyTcpfile ExecReload=/bin/kill -USR1 $MAINPID ; Use graceful shutdown with a reasonable timeout KillMode=mixed KillSignal=SIGQUIT TimeoutStopSec=5s ; Limit the number of file descriptors; see `man systemd.exec` for more limit settings. LimitNOFILE=1048576 ; Unmodified caddy is not expected to use more than that. LimitNPROC=512 ; Use private /tmp and /var/tmp, which are discarded after caddy stops. PrivateTmp=true ; Use a minimal /dev PrivateDevices=true ; Hide /home, /root, and /run/user. Nobody will steal your SSH-keys. ProtectHome=true ; Make /usr, /boot, /etc and possibly some more folders read-only. ProtectSystem=full [Install] WantedBy=multi-user.target
设置文件权限并启动服务
chmod 644 /etc/systemd/system/caddy.service && chmod 644 /etc/systemd/system/caddytcp.service && systemctl daemon-reload && systemctl start caddy.service && systemctl start caddytcp.service && systemctl enable caddy.service && systemctl enable caddytcp.service
编辑Caddyfile和CaddyTcpfile
/etc/caddy/Caddyfile
https://domain { root /usr/local/caddy/www/file timeouts none tls xxxx@gmail.com gzip proxy /home https://domain1:443 https://domain2:443 { websocket } }
/etc/caddy/CaddyTcpfile
proxy :31520 :31523 { host domain1,domain2,domain3 }
服务重启
systemctl restart caddytcp systemctl restart caddy
啰嗦几句:CADDY的好处就是不用编译一堆东西,直接一句命令安装完成,如果需要一键可以自己写个小脚本,懒,所以一键就算了。
至于要代理转发的内容就看各自的需求了,网页、应用、中国特色需求都可!