保存配置

安装 Clash

  • 确保你已经下载并安装了 Clash。
  • 打开终端(macOS/Linux)或命令提示符(Windows),进入 Clash 的配置目录:
    cd /Applications/Clash.app/Contents/Resources

    或者,如果你使用的是 Docker,可以直接运行 Clash 的 Docker 容器:

    docker run -d --name clash -p 789:789 -p 7891:7891 --volume /etc/clash:/etc/clash clash/clashd:latest

配置代理服务器

Clash 支持 HTTP 和 HTTPS 代理,以下是常见的代理配置示例:

HTTP 代理配置

{
  "proxy": {
    "http": "http://localhost:789",
    "https": "http://localhost:789"
  }
}

HTTPS 代理配置

{
  "proxy": {
    "http": "http://localhost:789",
    "https": "http://localhost:789"
  }
}

非本地代理(使用远程服务器)

{
  "proxy": {
    "http": "http://example.com:808",
    "https": "http://example.com:808"
  }
}

配置 DNS

Clash 支持自带的 DNS 解析功能,你可以手动配置 DNS 服务器:

{
  "dns": {
    "servers": [
      "8.8.8.8",
      "8.8.4.4"
    ]
  }
}

路由转发(SOCKS代理)

如果你想使用 SOCKS 代理,可以配置 Clash 的路由转发:

{
  "socks": {
    "listen": 7891,
    "destinations": [
      {
        "address": "...",
        "port": 0,
        "socks": "SOCKS://localhost:789"
      }
    ]
  }
}

负载均衡

Clash 支持负载均衡,可以将流量分发到多个服务器:

{
  "proxy": {
    "http": "http://server1:800,server2:800,server3:800",
    "https": "http://server1:8443,server2:8443,server3:8443"
  }
}

配置限速或过滤

你可以对 Clash 代理设置限速或过滤规则:

{
  "proxy": {
    "http": "http://localhost:789",
    "https": "http://localhost:789"
  },
  "filter": {
    "http": [
      {
        "domain": "example.com",
        "action": "block"
      }
    ],
    "https": [
      {
        "domain": "ads.example.com",
        "action": "block"
      }
    ]
  }
}

配置 WebSocket 代理

如果你需要代理 WebSocket 连接,可以这样配置:

{
  "proxy": {
    "ws": "ws://localhost:789"
  }
}

保存配置

将以上配置保存为 JSON 文件,通常放在 clash.yamlclash.json 文件中:



启动或重启 Clash

确保 Clash 已经启动,并且可以通过命令重启它:

# macOS/Linux
./clashctl start
./clashctl restart
# Windows
clash.exe start
clash.exe restart

测试代理配置

  • 打开浏览器,设置代理地址为 localhost:789localhost:7891(SOCKS 代理)。
  • 测试访问网页,确保代理正常工作。

日志管理

Clash 提供详细的日志记录,你可以查看日志以 troubleshooting:

# 查看日志
./clashctl logs

如果你遇到问题,可以参考 Clash 官方文档 或在社区求助,希望这些配置教程对你有帮助!

保存配置

扫码添加安易加速器官方微信

扫码添加安易加速器官方微信

021-64387251
扫码添加安易加速器官方微信

扫码添加安易加速器官方微信

网站地图