本节介绍了如何搭建xray服务器用于科学上网。

1. V2ray和Xray简介

Project V是一个工具集合,可以实现专属的基础通信网络。Project V 的核心工具称为V2Ray,其主要负责网络协议和功能的实现,与其它Project V通信。V2Ray 可以单独运行,也可以和其它工具配合,以提供简便的操作流程。从V2ray上面衍生了各种GUI程序被用于客户端。

2020年,V2ray原作者停止更新 V2Ray仓库 ,由 V2fly接管

2020年11月,因为开源许可证等原因XTLS被V2Ray社区从V2ray core移除,VLESS及XTLS的作者和支持者基于V2Ray另行组建了Project X组织。Xray-core 是 v2ray-core 的超集,具有更好的整体性能和 XTLS 等一系列增强,且完全兼容 v2ray-core 的功能及配置。

2. 安装

2.1. 服务器安装

直接版本:

bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install

配置等相关内容如下:

installed: /etc/systemd/system/xray.service
installed: /etc/systemd/system/xray@.service

installed: /usr/local/bin/xray
installed: /usr/local/etc/xray/*.json

installed: /usr/local/share/xray/geoip.dat
installed: /usr/local/share/xray/geosite.dat

installed: /var/log/xray/access.log
installed: /var/log/xray/error.log

2.2. 客户端安装

  • Windows: Clash等

  • Mac: V2rayU

3. 服务器配置Xray

3.1. 最简单版本: 任意端口,不采用fallback

服务器配置

 {
 "log": {
     "access": "/etc/v2ray/access.log",
      "error": "/etc/v2ray/error.log",
      "loglevel": "None"
  },
  "inbounds": [{
    "port": 10086,
    "protocol": "vmess",
    "settings": {
     "clients": [{ "id": "70bb5a14-d4f1-11ed-afa1-0242ac120002", "alterId": 64, "level": 0 }]
    }
  }],
   "outbounds": [{
     "protocol": "freedom",
     "settings": {}
   }]
}
  1. port代表服务器监听端口

  2. id采用UUID格式,可以使用`xray uuid`生成

启动服务端命令: xray run --config /etc/v2ray/config_base.json

客户端配置

{
  "log": {
    "error": "",
    "loglevel": "info",
    "access": ""
  },
  "inbounds": [
    {
      "listen": "0.0.0.0",
      "protocol": "socks",
      "settings": {
        "udp": false,
        "auth": "noauth"
      },
      "port": "1080"
    },
    {
      "listen": "0.0.0.0",
      "protocol": "http",
      "settings": {
        "timeout": 360
      },
      "port": "1087"
    }
  ],
  "outbounds": [
    {
      "mux": {
        "enabled": false,
        "concurrency": 8
      },
      "protocol": "vmess",
      "streamSettings": {
        "network": "tcp",
        "tcpSettings": {
          "header": {
            "type": "none"
          }
        },
        "security": "none"
      },
      "tag": "proxy",
      "settings": {
        "vnext": [
          {
            "address": "your-host-address",
            "users": [
              {
                "id": "70bb5a14-d4f1-11ed-afa1-0242ac120002",
                "alterId": 64,
                "level": 0,
                "security": "auto"
              }
            ],
            "port": 10086
          }
        ]
      }
    },
    {
      "tag": "direct",
      "protocol": "freedom",
      "settings": {
        "domainStrategy": "UseIP",
        "userLevel": 0
      }
    },
    {
      "tag": "block",
      "protocol": "blackhole",
      "settings": {
        "response": {
          "type": "none"
        }
      }
    }
  ],
  "dns": {},
  "routing": {
    "settings": {
      "domainStrategy": "AsIs",
      "rules": []
    }
  },
  "transport": {}
}
  1. port与id需要与服务器保持一致

  2. address输入服务器ip地址

3.2. VMESS + Web版本

1.安装acme来获取ssl证书 安装ACME 2. 配置服务器和nginx xray官方教程

5. 调试相关

  • 查看logging信息, 在服务器开启logging, 设置loglevel=info

  • systemctl status查看服务信息

  • journalctl -u xray.service -b查看logging