## 下载 GO 最新版
wget "https://go.dev/dl/$(curl https://go.dev/VERSION?m=text).linux-amd64.tar.gz"

## 解压至/usr/local/
tar -xf go*.linux-amd64.tar.gz -C /usr/local/

## 添加 Go 环境变量:
echo 'export GOROOT=/usr/local/go' >> /etc/profile
echo 'export PATH=$GOROOT/bin:$PATH' >> /etc/profile

## 使变量立即生效
source /etc/profile

go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest

cd /usr/local/bin

~/go/bin/xcaddy build --with github.com/caddyserver/forwardproxy@caddy2=github.com/klzgrad/forwardproxy@naive

mkdir -p /etc/caddy

vim /etc/caddy/config.json

{
 "apps": {
   "http": {
     "servers": {
       "srv0": {
         "listen": [
           ":11443"
         ],
         "routes": [
           {
             "handle": [
               {
                 "auth_user_deprecated": "username",
                 "auth_pass_deprecated": "password",
                 "handler": "forward_proxy",
                 "hide_ip": true,
                 "hide_via": true,
                 "probe_resistance": {}
               }
             ]
           },
           {
             "handle": [
               {
                 "handler": "reverse_proxy",
                 "headers": {
                   "request": {
                     "set": {
                       "Host": [
                         "{http.reverse_proxy.upstream.hostport}"
                       ],
                       "X-Forwarded-Host": [
                         "{http.request.host}"
                       ]
                     }
                   }
                 },
                 "transport": {
                   "protocol": "http",
                   "tls": {}
                 },
                 "upstreams": [
                   {
                     "dial": "example.com:443"
                   }
                 ]
               }
             ]
           }
         ],
         "tls_connection_policies": [
           {
             "match": {
               "sni": [
                 "$sni"
               ]
             },
             "certificate_selection": {
               "any_tag": [
                 "cert0"
               ]
             }
           }
         ],
         "automatic_https": {
           "disable": true
         }
       }
     }
   },
   "tls": {
     "certificates": {
       "load_files": [
         {
           "certificate": "$path",
           "key": "$path",
           "tags": [
             "cert0"
           ]
         }
       ]
     }
   }
 }
}
apt update
apt install nodejs npm
npm -v
npm install pm2 -g
pm2 -v
mkdir -p /var/log/caddy/
pm2 start caddy -n caddy -- run --config /etc/caddy/config.json  #run在前台运行,start在后台运行,用run便于pm2记录日志

或者直接

mkdir -p /var/log/caddy/
caddy start --config /etc/caddy/config.json

作者 Assaultcore

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注