Xray
개요
VLESS, VMess, Trojan, Shadowsocks 프로토콜을 Reality, XTLS-Vision, WebSocket, gRPC, HTTP/2 같은 현대적인 전송 방식과 함께 지원하는 고급 프록시 플랫폼인 Xray-core를 배포하고 구성합니다. 이 스킬은 서버 배포, 프로토콜 선택, TLS/Reality 구성, 트래픽 라우팅, 다중 사용자 관리, CDN 통합, 클라이언트 구성 및 모니터링을 다룹니다.
지침
1단계: 설치
bash -c "$(curl -L https://github.com/XTLS/Xray-install/raw/main/install-release.sh)" @ install
xray version
# 바이너리: /usr/local/bin/xray
# 설정: /usr/local/etc/xray/config.json
# UUID 및 X25519 키 생성
xray uuid
xray x25519 # Reality용 개인키 + 공개키 쌍
2단계: VLESS + Reality (권장)
가장 안전한 설정입니다. Reality는 실제 HTTPS 웹사이트의 TLS 핸드셰이크를 모방하므로 도메인이나 TLS 인증서가 필요하지 않습니다.
서버 설정 (/usr/local/etc/xray/config.json):
{
"log": { "loglevel": "warning" },
"inbounds": [{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{ "id": "YOUR-UUID", "flow": "xtls-rprx-vision", "email": "user1@proxy" }
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"dest": "www.microsoft.com:443",
"serverNames": ["www.microsoft.com", "microsoft.com"],
"privateKey": "YOUR-PRIVATE-KEY",
"shortIds": ["", "0123456789abcdef"]
}
},
"sniffing": { "enabled": true, "destOverride": ["http", "tls", "quic"] }
}],
"outbounds": [
{ "protocol": "freedom", "tag": "direct" },
{ "protocol": "blackhole", "tag": "block" }
],
"routing": {
"rules": [{ "type": "field", "ip": ["geoip:private"], "outboundTag": "block" }]
}
}
클라이언트 공유 링크:
vless://UUID@SERVER_IP:443?encryption=none&flow=xtls-rprx-vision&security=reality&sni=www.microsoft.com&fp=chrome&pbk=PUBLIC_KEY&sid=0123456789abcdef&type=tcp#MyProxy
systemctl enable --now xray
3단계: VLESS + WebSocket + TLS (CDN 호환)
서버 IP를 숨기기 위해 Cloudflare CDN을 통해 라우팅합니다. Cloudflare 프록시가 적용된 도메인과 TLS 인증서가 필요합니다.
apt install -y certbot
certbot certonly --standalone -d proxy.yourdomain.com
{
"inbounds": [
{
"port": 443, "protocol": "vless",
"settings": {
"clients": [{ "id": "YOUR-UUID" }],
"decryption": "none",
"fallbacks": [
{ "dest": 8080 },
{ "path": "/ws-path", "dest": 8443, "xver": 1 }
]
},
"streamSettings": {
"network": "tcp", "security": "tls",
"tlsSettings": {
"certificates": [{
"certificateFile": "/etc/letsencrypt/live/proxy.yourdomain.com/fullchain.pem",
"keyFile": "/etc/letsencrypt/live/proxy.yourdomain.com/privkey.pem"
}]
}
}
},
{
"listen": "127.0.0.1", "port": 8443, "protocol": "vless",
"settings": { "clients": [{ "id": "YOUR-UUID" }], "decryption": "none" },
"streamSettings": { "network": "ws", "wsSettings": { "path": "/ws-path" } }
}
],
"outbounds": [{ "protocol": "freedom", "tag": "direct" }]
}
8080 포트에서 대체 사이트(nginx)를 구성합니다. Cloudflare 설정: SSL/TLS 전체(엄격), WebSocket 활성화.
4단계: Trojan 및 Shadowsocks
Trojan (일반 HTTPS처럼 보임):
{
"inbounds": [{
"port": 443, "protocol": "trojan",
"settings": {
"clients": [{ "password": "your-strong-password", "email": "user1@trojan" }],
"fallbacks": [{ "dest": 8080 }]
},
"streamSettings": {
"network": "tcp", "security": "tls",
"tlsSettings": { "certificates": [{ "certificateFile": "...", "keyFile": "..." }] }
}
}]
}
Shadowsocks 2022 (최신 AEAD 암호):
{
"inbounds": [{
"port": 8388, "protocol": "shadowsocks",
"settings": { "method": "2022-blake3-aes-128-gcm", "password": "BASE64_KEY", "network": "tcp,udp" }
}]
}
키 생성: openssl rand -base64 16 (또는 aes-256의 경우 -base64 32)
5단계: 다중 사용자 관리
"clients": [
{ "id": "uuid-1", "email": "alice@proxy", "flow": "xtls-rprx-vision" },
{ "id": "uuid-2", "email": "bob@proxy", "flow": "xtls-rprx-vision" },
{ "id": "uuid-3", "email": "carol@proxy", "flow": "xtls-rprx-vision" }
]
사용자별 트래픽 통계 — 통계 API 활성화:
{
"stats": {},
"policy": {
"levels": { "0": { "statsUserUplink": true, "statsUserDownlink": true } },
"system": { "statsInboundUplink": true, "statsInboundDownlink": true }
},
"api": { "tag": "api", "services": ["StatsService", "HandlerService"] },
"inbounds": [
{ "listen": "127.0.0.1", "port": 10085, "protocol": "dokodemo-door",
"settings": { "address": "127.0.0.1" }, "tag": "api" }
],
"routing": { "rules": [{ "type": "field", "inboundTag": ["api"], "outboundTag": "api" }] }
}
런타임에 사용자 조회 및 관리:
xray api stats --server=127.0.0.1:10085 -name "user>>>alice@proxy>>>traffic>>>uplink"
xray api adi --server=127.0.0.1:10085 --inbound-tag proxy --id "new-uuid" --email "newuser@proxy"
xray api rmi --server=127.0.0.1:10085 --inbound-tag proxy --email "olduser@proxy"
6단계: 라우팅 규칙 및 모니터링
도메인/IP/지역별 라우팅:
{
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{ "type": "field", "domain": ["geosite:category-ads-all"], "outboundTag": "block" },
{ "type": "field", "ip": ["geoip:private"], "outboundTag": "block" },
{ "type": "field", "network": "tcp,udp", "outboundTag": "proxy" }
]
}
}
모니터링:
systemctl status xray
journalctl -u xray -f
grep "accepted" /var/log/xray/access.log | awk '{print $3}' | sort | uniq -c | sort -rn
방화벽:
ufw allow 443/tcp && ufw allow 443/udp && ufw enable
예시
예시 1: 소규모 팀을 위한 VLESS + Reality 프록시 서버 배포
사용자 요청: "Debian 12 VPS(198.51.100.30)에 Reality 전송 방식을 사용한 VLESS로 Xray를 설정해주세요. alice, bob, carol의 계정을 만들어주세요. Reality 대상으로 microsoft.com을 사용하고 v2rayNG용 공유 링크를 제공해주세요."
에이전트는 공식 스크립트로 Xray를 설치하고, 각 사용자의 UUID와 X25519 키 쌍을 생성한 후, config.json에 www.microsoft.com을 대상으로 하는 Reality 설정으로 443 포트의 VLESS 인바운드를 구성하고, xtls-rprx-vision 흐름의 세 클라이언트 항목을 추가하며, 개인 IP 차단 라우팅 규칙을 추가하고, xray 서비스를 활성화 및 시작하고, 방화벽에서 443 포트를 열고, 서버 IP, 공개 키, 짧은 ID, SNI를 포함한 세 개의 vless:// 공유 링크를 출력합니다.
예시 2: Cloudflare 및 대체 사이트를 통한 CDN 프론트 VLESS 프록시 설정
사용자 요청: "proxy.mysite.com이 Cloudflare를 통해 서버를 가리키고 있습니다. /secret-ws 경로에 VLESS over WebSocket을 사용하도록 Xray를 구성하여 트래픽이 Cloudflare CDN을 통과하도록 해주세요. 프록시가 아닌 방문자는 일반 nginx 웹사이트를 보게 해주세요."
에이전트는 certbot으로 Let's Encrypt 인증서를 획득하고, 443 포트에 기본 VLESS+TLS 인바운드를 구성하고 8080 포트의 nginx로 fallback을 설정하며, 로컬호스트 8443 포트에 /secret-ws 경로의 두 번째 VLESS+WebSocket 인바운드를 추가하고, 8080 포트에 정적 사이트를 제공하도록 nginx를 설정하며, Cloudflare SSL이 전체(엄격)로 설정되고 WebSocket이 활성화되었는지 확인하고, WebSocket 경로와 Cloudflare SNI가 포함된 클라이언트 연결 문자열을 제공합니다.
지침
- 새 배포에는 항상 VLESS + Reality를 사용하십시오. 도메인이나 인증서가 필요 없으며 가장 탐지 및 차단이 어려운 프로토콜입니다.
- 모든 VMess 사용자에 대해
"alterId": 0을 설정하여 강제 AEAD 암호화를 적용하십시오. 0이 아닌 alterId는 더 이상 사용되지 않는 덜 안전한 레거시 형식입니다. - 라우팅 규칙에서 개인 IP 범위(geoip:private)에 대한 액세스를 차단하여 프록시가 내부 서비스에 대한 SSRF 공격에 사용되지 않도록 하십시오.
xray api명령을 사용하여 서비스를 재시작하지 않고 런타임에 사용자를 추가 및 제거하면 활성 사용자 연결이 끊어지지 않습니다.- 서버와 다른 IP에서 호스팅되는 인기 웹사이트(microsoft.com, apple.com)에서 Reality
dest및serverNames을 선택하고 해당 사이트가 TLS 1.3 및 HTTP/2를 지원하는지 확인하십시오. - 사용자별 추적(
statsUserUplink/statsUserDownlink)이 포함된 통계 API를 활성화하여 대역폭 사용량을 모니터링하고 악용을 감지하십시오.