Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nginx反代配置https后 终端无法使用nginx反代配置https后 终端无法使用报错如下 是否需要修改前端ws:// 为wss:// #36

Open
chaoqunxie opened this issue Nov 8, 2023 · 0 comments

Comments

@chaoqunxie
Copy link

Terminal.vue:90 Mixed Content: The page at 'https://localhost:49001/#/terminal/console?containerId=b471c005e884&title=SimpleDocker%20%E5%AE%B9%E5%99%A8%E7%BB%88%E7%AB%AF%E6%8E%A7%E5%88%B6%E5%8F%B0' was loaded over HTTPS, but attempted to connect to the insecure WebSocket endpoint 'ws://localhost:49001/ws/api/container/terminal/8107896031ecdc7bac7b7774e23523b67373a264d836438b141a836b9378926d?containerId=b471c005e884&token=Bearer%20eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIyMDIzLTExLTA5VDA3OjM4OjQwLjU0NTYzMzU0MVoiLCJpYXQiOjE2OTk0MjkxMjAsInN1YiI6ImFkbWluIn0.JPqJE6lFOizcWmecuG-qdVnqKKTQt-pUd65gT5RPIwA'. This request has been blocked; this endpoint must be available over WSS.

nginx配置如下

upstream simpleDocker {
server 192.168.100.1:9001;
}

map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}

server {
listen 49001 ssl http2;
server_name 域名;
ssl_certificate /etc/nginx/ssl/域名_bundle.crt;
ssl_certificate_key /etc/nginx/ssl/域名.key;

if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot")
{
return 403;
}

location / {
proxy_pass http://simpleDocker;
proxy_redirect off;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;

  proxy_set_header Upgrade $http_upgrade;                              
  proxy_set_header Connection $connection_upgrade; 

}

  location /ws {
    proxy_pass http://simpleDocker; # 你的 WebSocket 后端服务地址
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host;
    # 根据需要设置代理读取超时时间
    proxy_read_timeout 86400; # 例如设置为 24 小时
} 

 location /ws/api/ {
    proxy_pass http://simpleDocker; # 代理到您的 WebSocket 服务
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $host;
    proxy_read_timeout 86400; # 设置适当的超时时间
} 

 location /websocket {                                                     
    proxy_pass http://simpleDocker; # ............... WebSocket ......
    proxy_http_version 1.1;                                           
    proxy_set_header Upgrade $http_upgrade;                              
    proxy_set_header Connection $connection_upgrade;                               
    proxy_set_header Host $host;                                         
    proxy_read_timeout 86400; # ...........................              
}  

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant