543 字
3 分钟
Xray的配置

本文章主要记录一些VPS的设置,使得购买的VPS及域名能够支持科学上网,服务器为Ubuntu 20.04。在执行任何操作之前,切换到/root目录,并使用apt update && apt upgrade来更新系统。

事前准备#

服务器准备#

部分软件:

Terminal window
apt install vim git curl wget -y

启用 BBR TCP 拥塞控制算法:

Terminal window
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
sysctl -p

设置时区:

Terminal window
timedatectl set-timezone Asia/Shanghai

Cloudflare准备#

将Cloudflare中SSL/TLS加密模式设置为完全(严格)

Cloudflare创建一个新的令牌(参考cf插件主页配置),权限为Zone.Zone.Read; Zone.DNS.Edit,并将令牌保存到本地。

Caddy官方下载地址,选择dns.provider.cloudflare,下载到本地准备。

设置密钥登陆#

生成密钥#

连接到服务器后,使用ssh-keygen来生成密钥,并把私钥保存到本地。

使用mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys更改公钥名称。使用如下命令来更改权限:

Terminal window
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

修改登录方式#

使用vim /etc/ssh/sshd_config来修改SSH配置文件,将PasswordAuthentication改为no,将PubkeyAuthentication改为yes,并systemctl restart ssh重启SSH服务。

如有必要,可以更改ssh的端口号,修改Port即可。

安装Caddy#

Terminal window
apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy

把之前下载的Caddy传到root下,

Terminal window
mv ./caddy_linux_amd64_custom ./caddy
chmod +x ./caddy
./caddy list-modules | grep dns

如果正常,会显示出dns.providers.cloudflare模块。

在替换官方的Caddy:

Terminal window
mv ./caddy /usr/bin/caddy

寻找合适的伪装站#

示例关键字:intext:登录 Cloudreve

配置Caddy#

启动Caddy服务:

Terminal window
systemctl enable --now caddy

通过如下命令查看Caddy的日志:

Terminal window
journalctl -u caddy --no-pager | less +G
Terminal window
vim /etc/caddy/Caddyfile

改为如下:

Terminal window
example.com {
encode gzip
tls {
dns cloudflare 你的API token
protocols tls1.2 tls1.3
}
reverse_proxy /rayws* localhost:port {
header_up Host {host}
header_up X-Real-IP {remote_host}
}
reverse_proxy /xuiws* localhost:port
# 伪装网址
reverse_proxy https://demo.cloudreve.org {
header_up Host {upstream_hostport}
}
}

奇怪的是xui只能在Chrome匿名模式下进入

caddy run查看tls是否生效:

Terminal window
tls.obtain certificate obtained successfully

XUI#

安装XUI#

参考官方仓库

Terminal window
bash <(curl -Ls https://raw.githubusercontent.com/FranzKafkaYu/x-ui/master/install.sh)

配置XUI#

进入面板,把监听IP改为127.0.0.1,端口改为上面定义的xuiws端口。添加端口为rayws端口的节点。

Xray的配置
https://blog.xiaobaizhang.top/posts/xray/
作者
张小白
发布于
2023-07-16
许可协议
CC BY-NC-SA 4.0