CREDIT: 16
398 字
2 分钟
MagicNet
请替换下面
${domain}部分为你的域名
domain = example.compassword = 114514local_port = 443初始配置
sudo vim /etc/ssh/sshd_configPermitRootLogin yesPasswordAuthentication yessudo vim /root/.ssh/authorized_keyssudo passwd usersudo passwd root下载
# 更新系统apt update -y && apt upgrade -y# 安装工具apt install socat nginx wget unzip -y# https://github.com/p4gefau1t/trojan-go/releases# 为 trojan-go 安置文件夹mkdir -p /opt/trojan-go/# 下载 trojan-go v0.10.6wget https://github.com/p4gefau1t/trojan-go/releases/download/v0.10.6/trojan-go-linux-amd64.zip -P /opt/trojan-go/# 解压unzip /opt/trojan-go/trojan-go-linux-amd64.zip -d /opt/trojan-go/配置 acme.sh
# 安装 acme.shcurl https://get.acme.sh | sh# 刷新环境source ~/.bashrc# 设置默认CA机构acme.sh --set-default-ca --server letsencrypt# 申请证书acme.sh --issue -d $domain --standalone -k ec-256 --force# 新建外部使用证书文件夹mkdir -p /ssl/$domain/# 发布到外部文件夹acme.sh --installcert -d $domain --fullchainpath /ssl/$domain/fullchain.crt --keypath /ssl/$domain/privkey.key --ecc --force配置 nginx
cat > /etc/nginx/sites-available/$domain << EOFserver { listen 80;
root /var/www/html; index index.html index.htm index.nginx-debian.html; server_name ${domain}; location / { try_files \$uri \$uri/ =404; }
if ( \$remote_addr != 127.0.0.1 ) { rewrite ^/(.*)$ https://${domain}/$1 redirect; }
access_log /var/log/nginx/${domain}.access.log; error_log /var/log/nginx/${domain}.error.log;}EOF
sed -i "s/\${domain}/$domain/g" /etc/nginx/sites-available/$domain# 启用虚拟主机(一个web服务)ln -s /etc/nginx/sites-available/$domain /etc/nginx/sites-enabled/
systemctl enable nginx --nowsystemctl stop nginxsystemctl start nginxsystemctl status nginx配置 trojan-go
cat > /opt/trojan-go/server.yaml << EOFrun-type: serverlocal-addr: 0.0.0.0local-port: ${local_port} # trojan服务的端口remote-addr: 127.0.0.1remote-port: 80 # 非法请求重定向password: - ${password} # 密码ssl: cert: /ssl/${domain}/fullchain.crt key: /ssl/${domain}/privkey.key sni: ${domain}router: enabled: true block: - 'geoip:private' geoip: /opt/trojan-go/geoip.dat geosite: /opt/trojan-go/geosite.datmux: enabled: truewebsocket: enabled: falseEOF
sed -i "s/\${domain}/$domain/g" /opt/trojan-go/server.yamlsed -i "s/\${local_port}/$local_port/g" /opt/trojan-go/server.yamlsed -i "s/\${password}/$password/g" /opt/trojan-go/server.yaml注册 trojan-go 系统服务
cat > /etc/systemd/system/trojan-go.service << EOF[Unit]Description=Trojan-Go - An unidentifiable mechanism that helps you bypass GFWDocumentation=https://p4gefau1t.github.io/trojan-goAfter=network.target nss-lookup.target
[Service]CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICEAmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICENoNewPrivileges=trueExecStart=/opt/trojan-go/trojan-go -config /opt/trojan-go/server.yamlRestart=on-failureRestartSec=10sLimitNOFILE=infinity
[Install]WantedBy=multi-user.targetEOF# 刷新守护进程配置systemctl daemon-reload
# 启用 trojan-go 服务systemctl enable trojan-go --nowsystemctl stop trojan-gosystemctl start trojan-gosystemctl status trojan-gotrojan://${password}@${domain}:${local_port}#Trojan-Server# https://github.com/CareyWang/sub-webhttps://bianyuan.xyz/