xray安装


下载:https://github.com/XTLS/Xray-core/releases
配置文档:https://xtls.github.io/config/

上传到/etc/xray目录后:
创建配置文件config.json

json
{
  "log": {
    "loglevel": "warning",
    "access": "/var/log/xray/access.log",
    "error": "/var/log/xray/error.log"
  },
  "inbounds": [
    {
      "listen": "127.0.0.1",
      "port": 8001,
      "protocol": "vless",
      "settings": {
        "clients": [
          {
            "id": "9dfa8d64-9ce1-4129-9808-355ff0b45d15"
          }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "xhttp",
        "xhttpSettings": {
          "path": "/路径地址",
          "mode": "auto"
        }
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "freedom",
      "tag": "direct"
    },
    {
      "protocol": "blackhole",
      "tag": "blocked"
    }
  ],
  "routing": {
    "rules": [
      {
        "type": "field",
        "ip": ["geoip:private"],
        "outboundTag": "blocked"
      }
    ]
  }
}
  • listen 设为 127.0.0.1,只接受本机(Caddy)转发过来的流量,不对外暴露。
  • mode: "auto" 会自动选择 stream-up / packet-up,兼容性最好。
  • path 一定要换成自己设定的、不容易被猜到的字符串。

系统启动文件:

ini
[Unit]
Description=xray
After=network.target nss-lookup.target

[Service]
User=root
CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE
NoNewPrivileges=true
LogsDirectory=xray
ExecStart=/etc/xray/xray run -config /etc/xray/config.json
Restart=on-failure
RestartPreventExitStatus=23
LimitNPROC=10000
LimitNOFILE=1000000

[Install]
WantedBy=multi-user.target

启动

bash
systemctl daemon-reload          # 重新加载 unit 文件
systemctl enable xray            # 开机自启
systemctl start xray             # 立即启动
systemctl status xray            # 查看状态

caddy配置,如果套CDN使用CF的源站证书,否则会因为套了CDN导致caddy申请不到证书而失败

config
# 不适用CND直连
域名 {
	encode gzip

    # XHTTP 路径反代到 Xray
    @xhttp {
        path /路径地址*
    }
    handle @xhttp {
        reverse_proxy 127.0.0.1:8001 {
            flush_interval -1
            header_up Host {host}
            header_up X-Real-IP {remote_host}
        }
    }

    # 其他路径伪装成普通网站
    handle {
        respond "Please access the API from the correct entry point" 200
    }
}

#时用CF证书套CDN
temu.5210010.xyz {
	encode gzip
	tls /home/ssl/5210010.xyz.cf.pem /home/ssl/5210010.xyz.cf.key
    # XHTTP 路径反代到 Xray
    @xhttp {
        path /muxiaoliang*
    }
    handle @xhttp {
        reverse_proxy 127.0.0.1:8001 {
            flush_interval -1
            header_up Host {host}
            header_up X-Real-IP {remote_host}
        }
    }

    # 其他路径伪装成普通网站
    handle {
        respond "Please access the API from the correct entry point" 200
    }
	
}