VLESS 是一个高性能的反向代理服务器,支持 WebSocket、HTTP/2 和 HTTP/3,以下是配置 VLESS 的指南,帮助你快速搭建一个高效的反向代理服务。
安装 VLESS
使用 Go 安装
go install github.com/vlessio/vless@latest
手动下载
下载最新的 VLESS 源码并解压:
# 解压并进入目录 tar -xzf vless-?.?.?-linux-?.?.?.tar.gz cd vless-?.?.?-linux-?.?.?
配置 VLESS
1 创建配置文件
VLESS 的配置文件通常位于 etc/vless 目录下,文件名为 vless.json。
{
"version": "2.x",
"listen": "...:2088",
"domain": "yourdomain.com",
"cert_file": "yourdomain.com.crt",
"key_file": "yourdomain.com.key",
"websocket": {
"enabled": true,
"listen": "...:8081",
"path": "/ws"
},
"routes": [
{
"url": "/api/*",
"handler": "reverseproxy",
"path": "/api",
"method": ["GET", "POST"]
},
{
"url": "/websocket",
"handler": "websocket",
"path": "/ws"
}
],
" middleware": [
{
"name": "compression",
"options": {
"enabled": true,
"compress_level": 9,
"min_size": 100
}
}
]
}
2 启动 VLESS
./vless serve -config vless.json
高级配置
1 WebSocket 配置
如果你需要 WebSocket 支持,确保 websocket 部分在配置文件中正确配置:
"websocket": {
"enabled": true,
"listen": "...:8081",
"path": "/ws",
"subprotocol": "wss",
"max_connections": 100
},
2 路由规则
- 简单路由:
{ "url": "/api/*", "handler": "reverseproxy", "path": "/api", "method": ["GET"] } - 更复杂的路由:
{ "url": "^/api/v1/user/(.*)", "handler": "reverseproxy", "path": "/api/v1/user", "method": ["GET"] }
3 压缩和缓存
- 启用 Gzip 压缩:
{ "name": "compression", "options": { "enabled": true, "compress_level": 9, "min_size": 100 } } - 缓存策略:
{ "name": "cache", "options": { "enabled": true, "max_age": 360, "store": "file", "prefix": "cache" } }
4 使用中间件
- Gunicorn:
gunicorn --bind 0...:2088 --workers 4 --timeout 120 --workers 4 --worker-class wworker:worker.fcgi --bind "...:2088" --workers 4 --timeout 120 -w vless:serve
注意事项
1 Golang 环境
确保你已经安装了 Go 1.17 或更高版本,并配置了正确的 Go 环境。
2 权限设置
确保 VLESS 有足够的权限运行,
sudo chown -R vless:www-data /path/to/vless
3 部署
建议将 VLESS 部署在高性能的服务器上,Nginx、Apache 或 Docker。
扩展功能
1 TLS 配置
如果需要 HTTPS,配置 TLS 证书:
{
"tls": {
"enabled": true,
"cert_file": "yourdomain.com.crt",
"key_file": "yourdomain.com.key",
"ca_file": "CA.crt",
"server_name": "yourdomain.com"
}
}
2 认证
集成 OAuth 或 JWT 认证:
{
"auth": {
"enabled": true,
"jwt": {
"secret": "your_jwt_secret",
"issuer": "your_issuer"
}
}
}
3 限流
限制请求速率:
{
"rate": {
"enabled": true,
"limit": 100,
"burst": 0,
"interval": 60
}
}
VLESS 是一个强大的反向代理工具,通过合理配置,可以轻松实现高性能的网络应用代理,希望以上指南对你有帮助!如果有更多问题,可以参考 VLESS 官方文档。




