技术讨论ws+tls+Nginx修改端口问题

查看 62|回复 5
作者:好男人文哥   
   
方式:ws+tls+Nginx
如下图,想在v2里多一个端口,例11111,确认添加开放


之后客户端日志报错:
[Warning] failed to handler mux client connection > proxy/vmess/outbound: failed to find an available destination > common/retry: [transport/internet/websocket: failed to dial WebSocket > transport/internet/websocket: failed to dial to (wss://服务器IP:11111/路径/): 301 Moved Permanently > websocket: bad handshake] > common/retry: all retry attempts failed
网站日志:
"GET /路径/ HTTP/1.1" 301 162 "-" "Go-http-client/1.1"
到此为止我的思路按照跳转301排查,
然后F12看下请求:

发现奇葩的调转到原https://ip:443上去了(也就是网站默认端口)
然后再检查我的NGINX配置:
server
{
    listen 80;
    listen 443 ssl http2;
    listen 11111 ssl http2;
    server_name 网站;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/网站;
    #SSL-START SSL related configuration, do NOT delete or modify the next line of commented-out 404 rules
    #error_page 404/404.html;
    #HTTP_TO_HTTPS_START
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
    #HTTP_TO_HTTPS_END
    ssl_certificate    /www/server/panel/vhost/cert/网站/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/网站/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;
                #SSL-END
    #ERROR-PAGE-START  Error page configuration, allowed to be commented, deleted or modified
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    #PHP-INFO-START  PHP reference configuration, allowed to be commented, deleted or modified
    include enable-php-00.conf;
    #PHP-INFO-END
    #REWRITE-START URL rewrite rule reference, any modification will invalidate the rewrite rules set by the panel
    include /www/server/panel/vhost/rewrite/网站.conf;
    #REWRITE-END
    # Forbidden files or directories
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }
    # Directory verification related settings for one-click application for SSL certificate
    location ~ \.well-known{
        allow all;
    }
    #Prohibit putting sensitive files in certificate verification directory
    if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
        return 403;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
    {
        expires      30d;
        error_log /dev/null;
        access_log off;
    }
    location ~ .*\.(js|css)?$
    {
        expires      12h;
        error_log /dev/null;
        access_log off;
    }
   
  location /路径/ { # 与 V2Ray 配置中的 path 保持一致
    if ($http_upgrade != "websocket") { # WebSocket协商失败时返回404
        return 404;
    }
    proxy_redirect off;
    proxy_pass http://127.0.0.1:XXXX; # 假设WebSocket监听在环回地址的XXXX端口上
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    # Show real IP in v2ray access.log
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }   
   
    access_log  /www/wwwlogs/网站.log;
    error_log  /www/wwwlogs/网站.error.log;
}
到此为止已经懵逼了,大佬们讨论下
PS:
1、NTP正常
2、443端口可用
3、IP正常

网站, 端口, 路径

xiaoqiang1998   
这里
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;
    }
gzk101   
已经被检查的搭墙方式,研究没有意义
冲浪麦浪花郎   
当面教,当面抓
* Linux常用命令:telinit 0 关闭系统
* 资源 https://t.me/MJJ_aliyundrive
* MJJ频道 https://t.me/wearemjj
* Linux命令大全 https://www.linuxcool.com
* DNS设置大全 https://dns.iui.im/
* 优质导航大全 https://www.chaidu.com/
* HostLoc频道 https://t.me/myhostloc
* A1Plus & G Suit & Workspace教育全局号https://sourl.cn/xq7iAZ
* OneDrive1T/5T网盘批发 iCloud苹果个人200G号https://nanguo.in/shop?ref=awtyBzywo
   

好男人文哥
OP
  

xiaoqiang1998 发表于 2023-9-17 01:59
这里
    if ($server_port !~ 443){
        rewrite ^(/.*)$ https://$host$1 permanent;

location /
好男人文哥
OP
  

gzk101 发表于 2023-9-17 02:00
已经被检查的搭墙方式,研究没有意义

现在有什么好的吗
您需要登录后才可以回帖 登录 | 立即注册

返回顶部