每年10月11月,我的v2ray服务总会出点问题。每次我也懒得查找原因,重装一次了事。为了方便,还是记录一下安装过程,方便每次的使用。由于我习惯于使用ubuntu的系统,部署linux服务器在没有特殊要求的情况下,还是会使用ubuntu的版本。
准备:
- VPS
- 域名
一、安装 & 配置 v2ray
根据 fhs-install-v2ray 安装 v2ray,在root权限下。
// 安装可执行文件和 .dat 数据文件
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
# systemctl enable v2ray
# systemctl start v2ray
安装最新发行的 geoip.dat 和 geosite.dat:
// 只更新 .dat 数据文件
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)
移除 V2Ray:
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove
v2ray 服务器配置
在安装完成后参阅 文档 了解配置文件语法,并自己完成适合自己的配置文件。过程中可参阅社区贡献的 配置文件模板(提请您注意这些模板复制下来以后是需要您自己修改调整的,不能直接使用)
配置文件位置/usr/local/etc/v2ray/config.json
该配置文件在我测试的时候还有些许问题,不是很顺利,具体是否每次都能成功,不做保证。还是请参考github.com/v2fly/v2ray-examples
{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"port": <v2ray-port>,
"listen": "127.0.0.1",
"tag": "vmess-inbound",
"protocol": "vmess",
"settings": {
"auth": "noauth",
"udp": false,
"ip": "127.0.0.1",
"clients": [
{
"id": "<uuid>",
"level": 0,
"alterId": 0,
},
]
},
"streamSettings": {
"network": "h2",
"security": "none",
"httpSettings": {
"path": "<http2-path>",
"host": ["<domain>"]
},
"tlsSettings": {
"serverName": "<domain>"
}
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
},
{
"type": "field",
"domain": ["geosite:category-ads"],
"outboundTag": "blocked"
}
]
},
"dns": {
"hosts": {
"domain:v2ray.com": "www.vicemc.net",
"domain:github.io": "pages.github.com",
"domain:wikipedia.org": "www.wikimedia.org",
"domain:shadowsocks.org": "electronicsrealm.com"
},
"servers": [
"1.1.1.1",
{
"address": "114.114.114.114",
"port": 53,
"domains": ["geosite:cn"]
},
"8.8.8.8",
"localhost"
]
},
"policy": {
"levels": {
"0": {
"uplinkOnly": 0,
"downlinkOnly": 0,
"bufferSize": 204800,
"handshake": 10
}
},
"system": {
"statsInboundUplink": false,
"statsInboundDownlink": false,
"statsOutboundUplink": false,
"statsOutboundDownlink": false
}
}
}
二、安装 & 配置 Caddy
按照 Caddy 的安装步骤 将 Caddy 安装到 VPS 上,在root权限下。
# apt install -y debian-keyring debian-archive-keyring apt-transport-https
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
# curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | tee /etc/apt/sources.list.d/caddy-stable.list
# apt update
# apt install caddy
相关指令:
## 启动 caddy 服务
# systemctl start caddy
## 停止
# systemctl stop caddy
## 重启
# systemctl restart caddy
## 查看 caddy 服务的状态,可以用于排错
# systemctl status caddy
## 重新加载 caddy 配置,例如修改了 /etc/caddy/Caddyfile 之后
# systemctl reload caddy
## 查看 caddy 运行日志
# journalctl -u caddy --no-pager | less +G
配置/etc/caddy/Caddyfile
# 你的域名
<domain> {
# [可选] 邮箱,用于注册证书,到期时会有通知,
tls <email>
# 以下两项是配置一个访问静态文件,不配也可以
# 指定静态文件路径
root * <root-path>
# 设置为静态文件服务器
file_server
# 反向代理,将流量代理到 VPS 上的 V2ray
# <http2-path> 替换为 http2 的 path, <v2ray-port> 替换为 v2ray 对应的 port
reverse_proxy <http2-path> localhost:<v2ray-port> {
header_up Host {host}
transport http {
versions h2c 2
}
}
}