20250418 更新:已升级至 Xbord+XrayR 方案半年,体验很不错,推荐
强烈推荐阅读 Github | XTLS / Xray-core,包含服务器安装核心、服务器一键脚本、服务器面板推荐、适用客户端推荐等等
SSH 远程登录 VPS
推荐 terminal:Tabby
- 交互现代化
- 内置 SFTP
- 有很多插件
- 可以自建服务
安全防护
新建非 root 用户
新建用户
bash1adduser <用户名>
安装 sudo 功能
bash1apt update && apt install sudo
修改 2.1.1 中新建用户的权限
bash1visudo
在
User Privilege Specification
下加入一行<用户名> ALL=(ALL:ALL) ALL
即可。若希望使用 root 权限时不额外输入密码,则输入<用户名> ALL=(ALL) NOPASSWD: ALL
。
SSH 远程登录程序设置
打开配置文件
bash1nano /etc/ssh/sshd_config
修改配置项:修改 ssh 端口&禁止 root 用户登录
找到
#Port 22
这行,去掉注释,将 22 改成想要改到的端口号找到
PermitRootLogin Yes
这一行,奖 yes 改成 no重启 ssh 服务,使修改生效
bash1systemctl restart ssh
使用新建的用户信息重新进行 ssh 远程连接
网站建设&证书管理
安装 1Panel
安装方法参考官网:1Panel
网站+证书配置
前提要求:使用的二级域名已经解析到服务器
创建网站
Responsive Image 按需选择网站类型
Responsive Image 设置反代 点击网站列表后面的“配置”按钮
Responsive Image Responsive Image 选择 1Panel 的端口添加证书
Responsive Image 这一步按照 1Panel 提示完成即可检查端口是否放行
Xray 服务端配置
参考:https://xtls.github.io/document/level-0/ch07-xray-server.html,忽略 tls 部分
安装 Xray
bash
bash
1wget https://github.com/XTLS/Xray-install/raw/main/install-release.sh
2sudo bash install-release.sh
3rm ~/install-release.sh
配置 Xray
- 生成 uuid
bash
bash
1xray uuid
- 创建日志专用文件夹,生成所需日志文件,赋予其他用户权限
bash
bash
1mkdir ~/xray_log
2touch ~/xray_log/access.log && touch ~/xray_log/error.log
3chmod a+w ~/xray_log/*.log
- 创建配置文件
注意点:
- 注意放行 xray 的 inbounds 端口
- 如果 xray 日志显示 fail 检查 log 文件的权限
bash
bash
1sudo nano /usr/local/etc/xray/config.json
参考教程中的文件内容:
json
json
1// REFERENCE:
2// <https://github.com/XTLS/Xray-examples>
3// <https://xtls.github.io/config/>
4// 常用的 config 文件,不论服务器端还是客户端,都有 5 个部分。外加小小白解读:
5// ┌─ 1*log 日志设置 - 日志写什么,写哪里(出错时有据可查)
6// ├─ 2_dns DNS-设置 - DNS 怎么查(防 DNS 污染、防偷窥、避免国内外站匹配到国外服务器等)
7// ├─ 3_routing 分流设置 - 流量怎么分类处理(是否过滤广告、是否国内外分流)
8// ├─ 4_inbounds 入站设置 - 什么流量可以流入 Xray
9// └─ 5_outbounds 出站设置 - 流出 Xray 的流量往哪里去
10{
11 // 1\\_日志设置
12 "log": {
13 "loglevel": "warning", // 内容从少到多: "none", "error", "warning", "info", "debug"
14 "access": "/home/vpsadmin/xray_log/access.log", // 改为你的日志地址:vpsadmin改为你的用户名
15 "error": "/home/vpsadmin/xray_log/error.log" // 改为你的日志地址:vpsadmin改为你的用户名
16 },
17 // 2_DNS 设置
18 "dns": {
19 "servers": [
20 "https+local://1.1.1.1/dns-query",
21 "localhost"
22 ]
23 },
24 // 3*分流设置
25 "routing": {
26 "domainStrategy": "IPIfNonMatch",
27 "rules": [
28 {
29 "type": "field",
30 "ip": [
31 "geoip:private"
32 ],
33 "outboundTag": "block"
34 },
35 {
36 // 3.2 防止服务器直连国内
37 "type": "field",
38 "ip": ["geoip:cn"],
39 "outboundTag": "block"
40 },
41 // 3.3 屏蔽广告
42 {
43 "type": "field",
44 "domain": [
45 "geosite:category-ads-all"
46 ],
47 "outboundTag": "block"
48 }
49 ]
50 },
51 // 4*入站设置
52 // 4.1 这里只写了一个最简单的 vless+xtls 的入站,因为这是 Xray 最强大的模式。如有其他需要,请根据模版自行添加。
53 "inbounds": [
54 {
55 "port": 66666, // 填写你想要部署到的端口,和1Panel配置的端口不一致
56 "protocol": "vless",
57 "settings": {
58 "clients": [
59 {
60 "id": "", // 填写你的 UUID
61 "flow": "xtls-rprx-vision",
62 "level": 0,
63 "email": "[email protected]" // 填写你的,好像没啥用
64 }
65 ],
66 "decryption": "none",
67 "fallbacks": [
68 {
69 "dest": 8080 // 1Panel反代的端口
70 }
71 ]
72 },
73 "streamSettings": {
74 "network": "tcp",
75 "security": "tls",
76 "tlsSettings": {
77 "alpn": "http/1.1",
78 "certificates": [
79 {
80 "certificateFile": "/docker/npm/letsencrypt/live/npm-1/fullchain.pem", // 改为你的地址
81 "keyFile": "/docker/npm/letsencrypt/live/npm-1/privkey.pem" // 改为你的地址
82 }
83 ]
84 }
85 }
86 }
87 ],
88 // 5*出站设置
89 "outbounds": [
90 {
91 "tag": "direct",
92 "protocol": "freedom"
93 },
94 {
95 "tag": "block",
96 "protocol": "blackhole"
97 }
98 ]
99}
- 启动 xray
bash
bash
1sudo systemctl start xray
- 查看 xray 状态
bash
bash
1sudo systemctl status xray
active (running)
说明正在运行
👉 更多 xray 管理语句:
若你需要暂时关闭
Xray
的服务,那就用stop
命令
bash
bash
1sudo systemctl stop xray
- 若你需要重启
Xray
的服务,那就用restart
命令
bash
bash
1sudo systemctl restart xray
- 若你需要禁用
Xray
的服务(电脑重启后禁止 Xray 自动运行),那就用disable
命令
bash
bash
1sudo systemctl disable xray
- 若你需要启用
Xray
的服务(电脑重启后确保 Xray 自动运行),那就用enable
命令
bash
bash
1sudo systemctl enable xray
Xray 客户端配置
参考:https://xtls.github.io/document/level-0/ch08-xray-clients.html