yum install epel-release -y
yum install nginx -y
yum install nginx-mod-stream -y
2.1 新建目录
mkdir /etc/nginx/tcp.d
2.2 增加如下文件内容到 /etc/nginx/tcp.d/stream.conf
stream {
map $ssl_preread_server_name $singbox {
trojan.example.com trojan;
ws.example.com trojan-websocket;
}
upstream trojan {
server 127.0.0.1:52000;
}
upstream trojan-websocket {
server 127.0.0.1:52001;
}
server {
listen 443 reuseport;
listen [::]:443 reuseport;
proxy_pass $singbox;
ssl_preread on;
proxy_protocol on;
}
}
2.3 编辑 /etc/nginx/nginx.conf, 在文件末尾添加如下一行
include /etc/nginx/tcp.d/*.conf;
2.4 编辑回流配置 /etc/nginx/conf.d/fallback.conf
server {
listen 80;
server_name trojan.example.com;
index index.html;
root /data/app/web/hy;
}
2.5 运行 nginx
systemctl start nginx
wget https://go.dev/dl/go1.20.linux-amd64.tar.gz
tar xzf go1.20.linux-amd64.tar.gz
mv go /opt/
ln -s /opt/go/bin/go /usr/local/bin/go
如果没有 wget 命令, 使用 yum install wget 安装
go install -v github.com/sagernet/sing-box/cmd/sing-box@lates
mv ~/go/bin/sing-box /opt/go/bin/
ln -s /opt/go/bin/sing-box /usr/local/bin/sing-box
{
"log": {
"level": "info"
},
"inbounds": [
{
"type": "trojan",
"tag": "trojan-in",
"listen": "127.0.0.1",
"listen_port": 52001,
"tcp_fast_open": true,
"udp_fragment": true,
"sniff": true,
"sniff_override_destination": false,
"udp_timeout": 300,
"proxy_protocol": true,
"proxy_protocol_accept_no_header": false,
"users": [
{
"name": "whatever",
"password": "YOUPASSWORD"
}
],
"tls": {
"enabled": true,
"server_name": "trojan.example.com",
"alpn": [
"http/1.1"
],
"min_version": "1.2",
"max_version": "1.3",
"certificate_path": "/etc/certs/cert.pem",
"key_path": "/etc/certs/key.pem"
},
"transport": {
"type": "ws",
"path": "/wss",
"max_early_data": 0,
"early_data_header_name": "Sec-WebSocket-Protocol"
}
}
],
"outbounds": [
{
"type": "direct",
"tag": "direct"
}
]
}
6.1 新建证书目录
mkdir /etc/certs
6.2 去 cloudflare 上生成证书, 分别命名为 cert.pem 和 key.pem, 然后上传到 /etc/certs/目录下
mkdir -p /data/logs
nohup sing-box run -c /etc/sing-box.conf > /data/logs/sing.log 2>&1 &
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.