搭建通过 cloudflare 代理的 sing-box 教程

2023-02-08 11:08:36 +08:00
 BigGodMan

1 安装 nginx

yum install epel-release -y
yum install nginx -y
yum install nginx-mod-stream -y

2. 配置 nginx

3. 安装 go

wget https://go.dev/dl/go1.20.linux-amd64.tar.gz
tar xzf go1.20.linux-amd64.tar.gz
mv go /opt/
ln -s /opt/go/bin/go /usr/local/bin/go
如果没有 wget 命令, 使用 yum install wget 安装

4. 安装 sing-box

go install -v github.com/sagernet/sing-box/cmd/sing-box@lates
mv ~/go/bin/sing-box /opt/go/bin/
ln -s /opt/go/bin/sing-box /usr/local/bin/sing-box

5. 编辑配置文件 /etc/sing-box.conf

{
  "log": {
    "level": "info"
  },
  "inbounds": [
    {
      "type": "trojan",
      "tag": "trojan-in",
      "listen": "127.0.0.1",
      "listen_port": 52001,
      "tcp_fast_open": true,
      "udp_fragment": true,
      "sniff": true,
      "sniff_override_destination": false,
      "udp_timeout": 300,
      "proxy_protocol": true,
      "proxy_protocol_accept_no_header": false,
      "users": [
        {
          "name": "whatever",
          "password": "YOUPASSWORD"
        }
      ],
      "tls": {
        "enabled": true,
        "server_name": "trojan.example.com",
        "alpn": [
          "http/1.1"
        ],
        "min_version": "1.2",
        "max_version": "1.3",
        "certificate_path": "/etc/certs/cert.pem",
        "key_path": "/etc/certs/key.pem"
      },
      "transport": {
        "type": "ws",
        "path": "/wss",
        "max_early_data": 0,
        "early_data_header_name": "Sec-WebSocket-Protocol"
      }
    }
  ],
  "outbounds": [
    {
      "type": "direct",
      "tag": "direct"
    }
  ]
}

6. ssl 证书

7. 启动

mkdir -p /data/logs
nohup sing-box run -c /etc/sing-box.conf > /data/logs/sing.log 2>&1 &
4152 次点击
所在节点    VPS
1 条回复
jtsang
2023-02-27 06:16:47 +08:00
这里 Cloudflare 只是提供了证书吧?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/914195

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX