### Install Xray with Homebrew Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/install.md Install Xray using Homebrew on Linux. ```bash brew install xray ``` -------------------------------- ### Install acme.sh Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-0/ch06-certificates.md Download and run the acme.sh installation script. Ensure you have wget installed. ```shell wget -O - https://get.acme.sh | sh ``` -------------------------------- ### DnsObject Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/dns.md A comprehensive example of the DnsObject configuration, illustrating hosts, servers, and other DNS-related settings. ```json { "dns": { "hosts": { "baidu.com": "127.0.0.1", "dns.google": ["8.8.8.8", "8.8.4.4"] }, "servers": [ "8.8.8.8", "8.8.4.4", { "address": "1.2.3.4", "port": 5353, "domains": ["domain:xray.com"], "expectedIPs": ["geoip:cn"], "skipFallback": false, "clientIP": "1.2.3.4" }, { "address": "https://8.8.8.8/dns-query", "domains": ["geosite:netflix"], "skipFallback": true, "queryStrategy": "UseIPv4" }, { "address": "https://1.1.1.1/dns-query", "domains": ["geosite:openai"], "skipFallback": true, "queryStrategy": "UseIPv6" }, "localhost" ], "clientIp": "1.2.3.4", "queryStrategy": "UseIP", "disableCache": false, "serveStale": false, "serveExpiredTTL": 0, "disableFallback": false, "disableFallbackIfMatch": false, "enableParallelQuery": false, "useSystemHosts": false, "tag": "dns_inbound" } } ``` -------------------------------- ### Installing wgcf-cli Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-2/warp.md This command installs the wgcf-cli tool, which is used for managing WireGuard configurations. ```bash bash -c "$(curl -L wgcf-cli.vercel.app)" ``` -------------------------------- ### Load Balancer Routing Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/routing.md An example of a complete routing configuration demonstrating inbound tags, balancer tags, and outbound configurations. ```json { "routing": { "rules": [ { "inboundTag": ["in"], "balancerTag": "round" } ], "balancers": [ { "selector": ["out"], "strategy": { "type": "roundRobin" }, "tag": "round" } ] }, "inbounds": [ { // Inbound config "tag": "in" } ], "outbounds": [ { // Outbound config "tag": "out1" }, { // Outbound config "tag": "out2" } ] } ``` -------------------------------- ### RawObject Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/transports/raw.md Example of outbound configuration using the raw network protocol with rawSettings. ```json { // outbound 示例,同样可用于 inbound "outbounds": [ { // ... "streamSettings": { "network": "raw", // [!code focus:6] "rawSettings": { "acceptProxyProtocol": false, "header": { "type": "none" } } } } ] } ``` -------------------------------- ### Nginx Installation Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-1/fallbacks-with-sni.md Commands to install Nginx from official repositories. ```bash sudo apt install curl gnupg2 ca-certificates lsb-release echo "deb [arch=amd64] http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \ | sudo tee /etc/apt/sources.list.d/nginx.list curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add - sudo apt update sudo apt install nginx ``` -------------------------------- ### Version Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/index.md An example of the 'version' configuration, which specifies the minimum and maximum compatible Xray versions for the configuration. ```json { "version": { "min": "25.8.3", "max": "" } } ``` -------------------------------- ### Install iptables and ip6tables Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-2/tproxy_ipv4_and_ipv6.md Installs the necessary iptables and ip6tables packages for transparent proxying. Use this command on Debian/Ubuntu-based systems. ```bash # sudo apt install iptables ip6tables ``` -------------------------------- ### RealityObject Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/transports/reality.md An example of how to configure RealityObject within Xray's stream settings, showing both inbound and outbound parameters. ```json { // outbound example; also applies to inbound "outbounds": [ { // ... "streamSettings": { "security": "reality", // [!code focus:30] "realitySettings": { // Inbound (server-side) settings "show": false, "target": "example.com:443", "xver": 0, "serverNames": ["example.com", "www.example.com"], "privateKey": "", "minClientVer": "", "maxClientVer": "", "maxTimeDiff": 0, "shortIds": ["", "0123456789abcdef"], "mldsa65Seed": "", "limitFallbackUpload": { "afterBytes": 0, "bytesPerSec": 0, "burstBytesPerSec": 0 }, "limitFallbackDownload": { "afterBytes": 0, "bytesPerSec": 0, "burstBytesPerSec": 0 }, // Outbound (client-side) settings "serverName": "", "fingerprint": "chrome", "password": "", "shortId": "", "mldsa65Verify": "", "spiderX": "" } } } ] } ``` -------------------------------- ### Query Strategy Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/dns.md Example demonstrating the use of queryStrategy for specific domains and globally. ```json { "dns": { "servers": [ "https://1.1.1.1/dns-query", { "address": "https://8.8.8.8/dns-query", "domains": ["geosite:netflix"], "skipFallback": true, "queryStrategy": "UseIPv4" // netflix 的域名查询 A 记录 }, { "address": "https://1.1.1.1/dns-query", "domains": ["geosite:openai"], "skipFallback": true, "queryStrategy": "UseIPv6" // openai 的域名查询 AAAA 记录 } ], "queryStrategy": "UseIP" // 全局同时查询 A 和 AAAA 记录 } } ``` -------------------------------- ### Install Additional OpenWrt Dependencies Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-2/iptables_gid.md Installs essential libraries for OpenWrt systems that might be missing and could prevent Xray from running. ```bash opkg install libopenssl ca-certificates ``` -------------------------------- ### Install Sudo Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch04-security.md Update package lists and install the `sudo` package, which allows permitted users to run commands as the superuser or another user. ```shell apt update && apt install sudo ``` -------------------------------- ### Install Xray with Gentoo Portage Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/install.md Install Xray on Gentoo systems after adding the Gentoo-zh overlay. This method is suitable for Systemd systems. ```bash layman -a gentoo-zh ``` ```bash eselect repository add gentoo-zh ; layman -a gentoo-zh ``` -------------------------------- ### Install Xray with yay (AUR) Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/install.md Use this command to install Xray via the Arch User Repository using the yay helper. ```bash yay -S xray ``` -------------------------------- ### Install openresolv Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-2/redirect.md Install the openresolv package if the DNS field is used in the WireGuard [Interface] section. This is a required dependency for proper DNS handling in such configurations. ```bash apt install openresolv ``` -------------------------------- ### Create Website Directory and Index File Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch05-webpage.md Creates a directory for your website content and initializes an index.html file using nano for editing. ```shell mkdir -p ~/www/webpage/ && nano ~/www/webpage/index.html ``` -------------------------------- ### Install iptables Modules on OpenWrt Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-2/iptables_gid.md Installs necessary iptables modules for tproxy and extra functionalities on OpenWrt systems. These are often required for Xray to operate correctly in a transparent proxy setup. ```bash opkg install sudo iptables-mod-tproxy iptables-mod-extra ``` -------------------------------- ### Basic Routing Object Configuration Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/routing.md Defines the top-level routing configuration, including domain strategy and arrays for rules and balancers. Use this as a starting point for your routing setup. ```json { "routing": { "domainStrategy": "AsIs", "rules": [], "balancers": [] } } ``` -------------------------------- ### Client Configuration File Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch08-xray-clients.md A comprehensive example of a client configuration file for xray-core, demonstrating settings for logging, DNS, routing, inbounds, and outbounds. It includes explanations for each section and placeholder values that need to be replaced with user-specific information. ```json // REFERENCE: // https://github.com/XTLS/Xray-examples // https://xtls.github.io/config/ // 常用的config文件,不论服务器端还是客户端,都有5个部分。外加小小白解读: // ┌─ 1_log 日志设置 - 日志写什么,写哪里(出错时有据可查) // ├─ 2_dns DNS-设置 - DNS怎么查(防DNS污染、防偷窥、避免国内外站匹配到国外服务器等) // ├─ 3_routing 分流设置 - 流量怎么分类处理(是否过滤广告、是否国内外分流) // ├─ 4_inbounds 入站设置 - 什么流量可以流入Xray // └─ 5_outbounds 出站设置 - 流出Xray的流量往哪里去 { // 1_日志设置 // 注意,本例中我默认注释掉了日志文件,因为windows, macOS, Linux 需要写不同的路径,请自行配置 "log": { // "access": "/home/local/xray_log/access.log", // 访问记录 // "error": "/home/local/xray_log/error.log", // 错误记录 "loglevel": "warning" // 内容从少到多: "none", "error", "warning", "info", "debug" }, // 2_DNS设置 "dns": { "servers": [ // 2.1 国外域名使用国外DNS查询 { "address": "1.1.1.1", "domains": ["geosite:geolocation-!cn"] }, // 2.2 国内域名使用国内DNS查询,并期待返回国内的IP,若不是国内IP则舍弃,用下一个查询 { "address": "223.5.5.5", "domains": ["geosite:cn"], "expectIPs": ["geoip:cn"] }, // 2.3 作为2.2的备份,对国内网站进行二次查询 { "address": "114.114.114.114", "domains": ["geosite:cn"] }, // 2.4 最后的备份,上面全部失败时,用本机DNS查询 "localhost" ] }, // 3_分流设置 // 所谓分流,就是将符合否个条件的流量,用指定`tag`的出站协议去处理(对应配置的5.x内容) "routing": { "domainStrategy": "IPIfNonMatch", "rules": [ // 3.1 广告域名屏蔽 { "domain": ["geosite:category-ads-all"], "outboundTag": "block" }, // 3.2 国内域名直连 { "domain": ["geosite:cn"], "outboundTag": "direct" }, // 3.3 国外域名代理 { "domain": ["geosite:geolocation-!cn"], "outboundTag": "proxy" }, // 3.4 走国内"223.5.5.5"的DNS查询流量分流走direct出站 { "ip": ["223.5.5.5"], "outboundTag": "direct" }, // 3.5 国内IP直连 { "ip": ["geoip:cn", "geoip:private"], "outboundTag": "direct" } // 3.6 默认规则 // 在Xray中,任何不符合上述路由规则的流量,都会默认使用【第一个outbound(5.1)】的设置,所以一定要把转发VPS的outbound放第一个 ] }, // 4_入站设置 "inbounds": [ // 4.1 一般都默认使用socks5协议作本地转发 { "tag": "socks-in", "protocol": "socks", "listen": "127.0.0.1", // 这个是通过socks5协议做本地转发的地址 "port": 10800, // 这个是通过socks5协议做本地转发的端口 "settings": { "udp": true } }, // 4.2 有少数APP不兼容socks协议,需要用http协议做转发,则可以用下面的端口 { "tag": "http-in", "protocol": "http", "listen": "127.0.0.1", // 这个是通过http协议做本地转发的地址 "port": 10801 // 这个是通过http协议做本地转发的端口 } ], // 5_出站设置 "outbounds": [ // 5.1 默认转发VPS // 一定放在第一个,在routing 3.6 里面已经说明了,这等于是默认规则,所有不符合任何规则的流量都走这个 { "tag": "proxy", "protocol": "vless", "settings": { "address": "a-name.yourdomain.com", // 替换成你的真实域名 "port": 443, "id": "uuiduuid-uuid-uuid-uuid-uuiduuiduuid", // 和服务器端的一致 "flow": "xtls-rprx-vision", "encryption": "none", "level": 0 }, "streamSettings": { "network": "tcp", "security": "tls", "tlsSettings": { "serverName": "a-name.yourdomain.com", // 替换成你的真实域名 "allowInsecure": false, // 禁止不安全证书 "fingerprint": "chrome" // 通过 uTLS 库 模拟 Chrome / Firefox / Safari 或随机生成的指纹 } } }, // 5.2 用`freedom`协议直连出站,即当routing中指定'direct'流出时,调用这个协议做处理 { "tag": "direct", "protocol": "freedom" }, // 5.3 用`blackhole`协议屏蔽流量,即当routing中指定'block'时,调用这个协议做处理 { "tag": "block", "protocol": "blackhole" } ] } ``` -------------------------------- ### FakeDNS Coexisting with DNS Routing Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/fakedns.md Example demonstrating how to configure FakeDNS with specific domains to ensure high priority within a DNS routing setup. ```json { "dns": { "servers": [ { "address": "fakedns", "domains": [ // Consistent with the content used for routing below "geosite:cn", "domain:example.com" ] }, { "address": "1.2.3.4", "domains": ["geosite:cn"], "expectIPs": ["geoip:cn"] }, { "address": "1.1.1.1", "domains": ["domain:example.com"] }, "8.8.8.8" ] } } ``` -------------------------------- ### Correct Routing Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/ru/document/level-1/routing-lv1-part2.md This configuration demonstrates how to correctly separate different matching criteria into distinct rules for effective routing. ```json { "routing": { "domainStrategy": "AsIs", "rules": [ { "ip": ["223.5.5.5"], "outboundTag": "direct-out" }, { "domain": ["full:direct.yourdomain.com"], "outboundTag": "direct-out" } ] } } ``` -------------------------------- ### Observatory Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/observatory.md Configure the background connection observatory. Use this to set the probe URL, interval, and concurrency behavior for outbound proxies. ```json { "observatory": { "subjectSelector": ["outbound"], "probeUrl": "https://www.google.com/generate_204", "probeInterval": "10s", "enableConcurrency": false } } ``` -------------------------------- ### Install Nginx Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch05-webpage.md Installs the Nginx web server on Debian-based systems. Ensure your system is updated before installation. ```shell sudo apt update && sudo apt install nginx ``` -------------------------------- ### Install acme.sh Certificate Manager Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch06-certificates.md Download and install the acme.sh script. This command fetches the latest version and runs the installation. ```shell wget -O - https://get.acme.sh | sh ``` -------------------------------- ### 更新 Debian 软件列表 Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-0/ch03-ssh.md 使用 apt 包管理器查询可用的软件更新信息。 ```shell apt update ``` -------------------------------- ### Install Xray with pacman (Arch Linux CN) Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/install.md Install Xray using pacman after adding the Arch Linux CN repository. Requires root privileges. ```bash pacman -S xray ``` -------------------------------- ### Add a new user to the system Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-0/ch04-security.md Use this command to create a new user account and set its initial password. Follow the prompts for user information, but you can skip most by pressing Enter. ```shell adduser vpsadmin ``` -------------------------------- ### Create Website Directory and HTML File Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-0/ch05-webpage.md Use this command to create a directory for your website and open an HTML file for editing. ```shell mkdir -p ~/www/webpage/ && nano ~/www/webpage/index.html ``` -------------------------------- ### HTTPResponseObject Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/transports/raw.md Example configuration for HTTPResponseObject used in HTTP header masquerading. ```json { "version": "1.1", "status": "200", "reason": "OK", "headers": { "Content-Type": ["application/octet-stream", "video/mpeg"], "Transfer-Encoding": ["chunked"], "Connection": ["keep-alive"], "Pragma": "no-cache" } } ``` -------------------------------- ### HTTPRequestObject Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/transports/raw.md Example configuration for HTTPRequestObject used in HTTP header masquerading. ```json { "version": "1.1", "method": "GET", "path": ["/"], "headers": { "Host": ["www.baidu.com", "www.bing.com"], "User-Agent": [ "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36", "Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46" ], "Accept-Encoding": ["gzip, deflate"], "Connection": ["keep-alive"], "Pragma": "no-cache" } } ``` -------------------------------- ### GRPCObject Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/transports/grpc.md Example of GRPCObject configuration within streamSettings for outbound. ```json { "outbounds": [ { // ... "streamSettings": { "network": "grpc", // [!code focus:10] "grpcSettings": { "authority": "grpc.example.com", "serviceName": "name", "multiMode": false, "user_agent": "custom user agent", "idle_timeout": 60, "health_check_timeout": 20, "permit_without_stream": false, "initial_windows_size": 0 } } } ] } ``` -------------------------------- ### BurstObservatory Configuration Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/observatory.md Configure the burst connection observatory. This is used for probing outbound proxies with a burst of connections. ```json { "burstObservatory": { "subjectSelector": ["outbound"], "pingConfig": {} } } ``` -------------------------------- ### Install acme.sh and Apply for TLS Certificate Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-1/fallbacks-with-sni.md Installs acme.sh, sets the Cloudflare API token, applies for a certificate using DNS-01 validation, and installs the certificate to a specified directory. Ensure you are running these commands as the root user. ```bash curl https://get.acme.sh | sh export CF_Token="sdfsdfsdfljlbjkljlkjsdfoiwje" acme.sh --issue -d example.com -d *.example.com --dns dns_cf mkdir /etc/ssl/xray acme.sh --install-cert -d example.com --fullchain-file /etc/ssl/xray/cert.pem --key-file /etc/ssl/xray/privkey.key --reloadcmd "chown nobody:nogroup -R /etc/ssl/xray && systemctl restart xray" ``` -------------------------------- ### Clone Xray Source Code and Download Dependencies Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/development/intro/compile.md Use git to clone the Xray-core repository and then download the necessary Go modules. This is the initial step before building. ```bash git clone https://github.com/XTLS/Xray-core.git cd Xray-core && go mod download ``` -------------------------------- ### Install HAProxy Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-2/nginx_or_haproxy_tls_tunnel.md Package manager commands to install HAProxy on Arch Linux (pacman) or Debian/Ubuntu (apt). ```bash pacman -Su haproxy apt install haproxy ``` -------------------------------- ### Run Xray Client with Configuration Source: https://github.com/xtls/xray-docs-next/blob/main/docs/document/level-2/iptables_gid.md Starts the Xray client using a specified configuration file, running it in the background. This command is typically executed after setting the maximum open file descriptors. ```bash ulimit -SHn 1000000 sudo -u xray_tproxy xray -c /etc/xray/config.json & ``` -------------------------------- ### Hysteria User Object Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/config/inbounds/hysteria.md Example JSON structure for a Hysteria UserObject. ```json { "auth": "5783a3e7-e373-51cd-8642-c83782b807c5", "level": 0, "email": "love@xray.com" } ``` -------------------------------- ### VLESS User Object Example Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/config/inbounds/vless.md A basic VLESS user object configuration. ```json { "id": "5783a3e7-e373-51cd-8642-c83782b807c5", "level": 0, "email": "love@xray.com", "flow": "xtls-rprx-vision", "reverse": {} } ``` -------------------------------- ### Grant executable permission to install script Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-2/tproxy_ipv4_and_ipv6.md Makes the install-release.sh script executable. This is a prerequisite for local installation of Xray. ```bash # chmod 700 install-release.sh ``` -------------------------------- ### Execute Software Updates Source: https://github.com/xtls/xray-docs-next/blob/main/docs/en/document/level-0/ch03-ssh.md Use this command to install the updates that were found by 'apt update'. You will be prompted to confirm the installation. ```shell apt upgrade ```