适用对象:
- 低配 VPS(1 核 / 256MB / 10GB)
- NAT / LXD / 端口映射型 VPS
- 目标:安全、稳定、速度优先、可长期运行
本文不是一键脚本,而是在真实环境中完整跑通、可验证、可维护的方案。
在 低配 + NAT VPS 上,正确思路不是“功能越多越好”,而是:
Xray-core + VLESS + TCP
- 无域名:VLESS + TCP(基础可用)
- 有域名:VLESS + TCP + TLS(最终形态)
这两种方案 共用同一套 Xray 配置结构,后期可以无缝升级。
| 公网端口 | 容器端口 | 用途 |
|---|---|---|
| 27207 | 22 | SSH |
| 21468 | 443 | Xray |
⚠️ 外部访问必须使用 公网端口,不是容器端口。
bashapt update && apt upgrade -y
apt install -y curl unzip socat cron
cd /usr/local/bin
curl -L -o xray.zip https://github.com/XTLS/Xray-core/releases/latest/download/Xray-linux-64.zip
unzip xray.zip
chmod +x xray
xray version
生成 UUID:
bashxray uuid
适合场景:
- 没有域名
- 想先跑通、确认稳定性
- 内部或个人使用
/etc/xray/config.json
json{
"log": { "loglevel": "warning" },
"inbounds": [
{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{ "id": "YOUR_UUID" }
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp"
}
}
],
"outbounds": [ { "protocol": "freedom" } ]
}
创建 systemd 服务:
bashcat > /etc/systemd/system/xray.service << 'EOF'
[Unit]
Description=Xray Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/xray run -config /etc/xray/config.json
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable xray
systemctl restart xray
验证监听:
bashss -lntp | grep 443
textvless://YOUR_UUID@VPS_IP:21468?encryption=none&type=tcp#vps-notls
说明:
- 使用 IP + 公网端口
- 无 TLS,协议简单,稳定性高
适合场景:
- 有可控域名(一级或自有二级域名)
- 希望更安全、更像正常 HTTPS
- 长期使用
textvps.example.com -> VPS 公网 IP (仅 DNS,灰云)
bashcurl https://get.acme.sh | sh
/root/.acme.sh/acme.sh --set-default-ca --server letsencrypt
export CF_Token="YOUR_CF_TOKEN"
/root/.acme.sh/acme.sh --issue --dns dns_cf -d vps.example.com
mkdir -p /etc/xray/cert
/root/.acme.sh/acme.sh --install-cert -d vps.example.com \
--key-file /etc/xray/cert/key.pem \
--fullchain-file /etc/xray/cert/cert.pem
json{
"log": { "loglevel": "warning" },
"inbounds": [
{
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{ "id": "YOUR_UUID" }
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "tls",
"tlsSettings": {
"certificates": [
{
"certificateFile": "/etc/xray/cert/cert.pem",
"keyFile": "/etc/xray/cert/key.pem"
}
]
}
}
}
],
"outbounds": [ { "protocol": "freedom" } ]
}
重启并验证:
bashsystemctl restart xray ss -lntp | grep 443
textvless://YOUR_UUID@vps.example.com:21468?encryption=none&security=tls&type=tcp#vps-tls
⚠️ TLS 模式 必须使用域名,不能用 IP。
bashcurl ifconfig.me
返回 VPS 公网 IP 即成功。
bashapt install tcpdump tcpdump -ni eth0 tcp port 443
看到 SYN → SYN/ACK → ACK 表示链路完全正常。
少即是多,简单即是稳定。
v2ray 剪贴板导入:

本文作者:Vivian
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!