2022-11-13 17:22:21 更新一键安装脚本
一键安装
安装Nginx
申请证书
安装Xray
给Xray配置TLS证书
配置Xray
优化
一键安装
1
| wget -N --no-check-certificate -q -O xray.sh "https://raw.githubusercontent.com/uerax/xray-script/master/xray.sh" && chmod +x xray.sh && bash xray.sh
|
安装nginx
1 2 3 4 5
| sudo apt update && sudo apt install -y nginx mkdir -p /home/xray/webpage/ && cd /home/xray/webpage/
apt install unzip && wget -O web.zip --no-check-certificate https://html5up.net/phantom/download && unzip web.zip && rm web.zip
|
修改nginx.conf
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
sed -i '/\/etc\/nginx\/sites-enabled\//d' /etc/nginx/nginx.conf
cat>/etc/nginx/conf.d/xray.conf<<EOF server { listen 80; server_name yourdomain; root /home/xray/webpage/; index index.html; } EOF
sed -i 's/yourdomain/你的域名/' /etc/nginx/conf.d/xray.conf
systemctl reload nginx
|
申请证书
1 2 3 4 5 6 7 8
| wget -O - https://get.acme.sh | sh && cd ~ && . .bashrc acme.sh --upgrade --auto-upgrade acme.sh --issue --server letsencrypt --test -d 你的域名 -w /home/xray/webpage --keylength ec-256
acme.sh --set-default-ca --server letsencrypt acme.sh --issue -d 你的域名 -w /home/xray/webpage --keylength ec-256 --force
|
安装Xray
脚本安装
1 2
| wget https://github.com/XTLS/Xray-install/raw/main/install-release.sh && bash install-release.sh && rm install-release.sh
|
手动安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| wget https://github.com/XTLS/Xray-core/releases/download/v1.5.10/Xray-linux-64.zip -O xray.zip && unzip xray.zip -d /root/xray/ && rm xray.zip
cat>/etc/systemd/system/xray.service<<EOF [Unit] Description=Xray Service Documentation=https://github.com/xtls After=network.target nss-lookup.target [Service] User=root CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE AmbientCapabilities=CAP_NET_ADMIN CAP_NET_BIND_SERVICE NoNewPrivileges=true ExecStart=/root/xray/xray run -config /usr/local/etc/xray/config.json Restart=on-failure RestartPreventExitStatus=23 LimitNPROC=10000 LimitNOFILE=1000000 [Install] WantedBy=multi-user.target EOF
|
给Xray配置TLS证书
1
| mkdir -p /home/xray/xray_cert && acme.sh --install-cert -d 你的域名 --ecc --fullchain-file /home/xray/xray_cert/xray.crt --key-file /home/xray/xray_cert/xray.key && chmod +r /home/xray/xray_cert/xray.key
|
自动更新临期证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| cat>/home/xray/xray_cert/xray-cert-renew.sh<<EOF #!/bin/bash
/root/.acme.sh/acme.sh --install-cert -d yourdomain --ecc --fullchain-file /home/xray/xray_cert/xray.crt --key-file /home/xray/xray_cert/xray.key echo "Xray Certificates Renewed"
chmod +r /home/xray/xray_cert/xray.key echo "Read Permission Granted for Private Key"
sudo systemctl restart xray echo "Xray Restarted" EOF
sed -i 's/yourdomain/你的域名/' /home/xray/xray_cert/xray-cert-renew.sh
|
创建定时任务
1 2 3
| chmod +x /home/xray/xray_cert/xray-cert-renew.sh
( crontab -l | grep -v "0 1 1 * * bash /home/xray/xray_cert/xray-cert-renew.sh"; echo "0 1 1 * * bash /home/xray/xray_cert/xray-cert-renew.sh" ) | crontab -
|
配置Xray
1 2 3 4 5 6
| xray uuid
mkdir /home/xray/xray_log && touch /home/xray/xray_log/access.log && touch /home/xray/xray_log/error.log && chmod a+w /home/xray/xray_log/*.log
|
模板文件修改
1 2 3 4 5 6
| wget https://raw.githubusercontent.com/XTLS/Xray-examples/main/Trojan-TCP-XTLS/config_server.json -O /usr/local/etc/xray/config.json
sed -i 's/\/path\/to\/cert/\/home\/xray\/xray_cert\/xray.crt/' /usr/local/etc/xray/config.json
sed -i 's/\/path\/to\/key/\/home\/xray\/xray_cert\/xray.key/' /usr/local/etc/xray/config.json
|
启动Xray
1 2 3 4
| // 脚本安装方式 systemctl start xray && systemctl enable xray // 手动安装方式
|
优化
开启bbr
开启 HTTP 自动跳转 HTTPS
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| sed -i '/\/home\/xray\/webpage\//d' /etc/nginx/conf.d/xray.conf sed -i '/index/d' /etc/nginx/conf.d/xray.conf
sed -i '3a \\treturn 301 https://$http_host$request_uri;' /etc/nginx/conf.d/xray.conf
cat>>/etc/nginx/conf.d/xray.conf<<EOF server { listen 127.0.0.1:8080; root /home/xray/webpage/; index index.html; add_header Strict-Transport-Security "max-age=63072000" always; } EOF
systemctl restart nginx
sed -i '19,24d' /usr/local/etc/xray/config.json
sudo sed -i 's/\"dest\".*/"dest": 8080/g' /usr/local/etc/xray/config.json
systemctl restart xray
|