最近在研究xray的xtls等功能,因为需要用在443端口上,因此需要讲443端口从https让出来。我这次是用的8443端口走https
1、开放8443端口
2、最好先关闭Nginx和xray等程序
3、修改Nginx的相关端口,需要注意的是BT里的所有网站均不能再使用443端口,所以如果有多个网站共用443端口,其他网站也要做端口转移
3.1 80端口的转移,我这里利用了301代码
server{
listen 80;
server_name yourhost.com; #修改为自己的域名
return 301 https://$host:8443$request_uri; #端口改为自己想要的https端口
}
3.2 443端口移交以及8443端口监听
server{
#listen 443 #删除443端口
listen 8443 ssl; #改用8443,Nginx从1.5开始不建议ssl单独作为命令,建议使用listen的参数使用,低版本此处为listen 8443 https2,在SSL出需追加ssl on语句
server_name yourhost.com; #修改为自己的域名
index index.php index.html index.htm default.php default.htm default.html;
root /www/wwwroot/yourhost.com/;
.
.
.
if ($server_port !~ 8443){ #修改为自己的端口
rewrite ^(/.*)$ https://$host$1 permanent;
}
#HTTP_TO_HTTPS_END
ssl_certificate /www/server/panel/vhost/cert/yourhost.com/fullchain.pem;
ssl_certificate_key /www/server/panel/vhost/cert/yourhost.com/privkey.pem;
.
.
.
error_page 497 301 =307 https://$host:8443$request_uri; #追加语句,确保所有错误代码均转向8443端口
.
.
.
}
3.3 重启Nginx试试,访问http://yourhost.com是不是自动转向https://yourhost.com:8443
4、此时443端口可以空出来给xray等其他程序使用了,模版参照https://github.com/XTLS/Xray-examples/tree/main/VLESS-TCP-XTLS-WHATEVER
VLESS over TCP with XTLS + 回落 & 分流 to WHATEVER(终极配置)
这里是 [进阶配置]的超集,利用 VLESS
强大的回落分流特性,实现了 443 端口尽可能多的协议、配置的完美共存,包括 [XTLS Direct
Mode](https://github.com/rprx/v2fly-github-io/blob/master/docs/config/protocols/vless.md#xtls-%E9%BB%91%E7%A7%91%E6%8A%80)客户端可以同时通过下列方式连接到服务器,其中 WS 都可以通过 CDN
- VLESS over TCP with XTLS,数倍性能,首选方式
- VLESS over TCP with TLS
- VLESS over WS with TLS
- VMess over TCP with TLS,不推荐
- VMess over WS with TLS
- Trojan over TCP with TLS
这里设置默认回落到 Xray 的 Trojan 协议,再继续回落到 80 端口的 Web 服务器(也可以换成数据库、FTP 等)
你还可以配置回落到 Caddy 的 forwardproxy 等其它也防探测的代理,以及分流到任何支持 WebSocket
的代理,都没有问题
5、这里有个问题要注意,xray可能不能使用pem文件作为ssl证书的依据,需要转化为crt和key的格式
确保有安装openssl
5.1.pem转crt格式
openssl x509 -in fullchain.pem -out fullchain.crt
具体用法为:
cd ..
openssl x509 -in /etc/letsencrypt/archive/domain/fullchain1.pem -out /etc/letsencrypt/archive/domain/fullchain1.crt
然后在这个路径找到转换好的证书/etc/letsencrypt/archive/domain
5.2.pem转key格式
openssl rsa -in privkey.pem -out privkey.key
具体用法为:
cd ..
openssl rsa -in /etc/letsencrypt/archive/domain/privkey1.pem -out /etc/letsencrypt/archive/domain/privkey1.key
然后在这个路径找到转换好的证书/etc/letsencrypt/archive/domain
5.3 建立一个定时任务,定期讲pem转换为crt和key文件
6、ubuntu系统里对xray的nobody用户配置可能有问题,记得修改xray.service里user=nobody为root。然后systemctl daemon-reload
, 重新启动
7、这样操作只有就可以用xray的前置,nginx作为后置通知有ssl,但是ssl是每三个月要更新一次,因为443和80都被用了,acme更新证书会有问题。
7.1 建立默认网站配置模版
复制/www/server/panel/vhost/nginx
里网站配置,重命名为shyper.cf.conf.1
复制/www/server/panel/vhost/nginx
里网站配置,重命名为shyper.cf.conf.default,修改配置80和443端口
删除301跳转,删除443跳转
7.2 原理
1、关闭xray,释放出80和443
2、重置网站,监听80和443
3、更新证书
4、转换证书做为xray使用
5、还原网站配置
6、启动xray,完成更新
cd ..
echo -------------
echo 1/9 关闭xray
systemctl stop xray
echo -------------
echo 2/9 替换网站配置文件
/bin/cp -rf /www/server/panel/vhost/nginx/shyper.cf.conf.default /www/server/panel/vhost/nginx/shyper.cf.conf
echo -------------
echo 3/9 重启Nginx
/etc/init.d/nginx reload
echo -------------
echo 5/9 开始更新证书
/www/server/panel/pyenv/bin/python -u /www/server/panel/class/acme_v2.py --renew=1
echo -------------
echo 6/9 还原配置文件
/bin/cp -rf /www/server/panel/vhost/nginx/shyper.cf.conf.1 /www/server/panel/vhost/nginx/shyper.cf.conf
echo -------------
echo 7/9 重启Nginx
/etc/init.d/nginx reload
echo -------------
echo 8/9 开始转换证书
openssl x509 -in /www/server/panel/vhost/cert/shyper.cf/fullchain.pem -out /usr/local/etc/xray/cert/cert.crt
openssl rsa -in /www/server/panel/vhost/cert/shyper.cf/privkey.pem -out /usr/local/etc/xray/cert/private.key
echo -------------
echo 9/9 重启xray
systemctl start xray
评论已关闭