taoes / SimpleDocker

🐳 🔥 SimpleDocker 是一个简单的Docker控制面板,致力于可以让开发者更方便,更无障碍的使用Docker, 其界面简洁,操作便捷,更多功能欢迎探索 !
https://www.zhoutao123.com/blog.html
GNU General Public License v2.0
272 stars 42 forks source link

nginx反代配置https后 终端无法使用 #35

Closed chaoqunxie closed 8 months ago

chaoqunxie commented 8 months ago

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.

taoes commented 8 months ago

终端功能依赖于 WebSocket,Nginx 也需要相应配置,请参考 https://tutorials.tinkink.net/zh-hans/nginx/nginx-websocket-reverse-proxy.html 配置,使得Nginx支持代理WS

chaoqunxie commented 8 months ago

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; # ...........................              
}  

} 配置这个 还是报错 是不是需要修改前端代码 ws:// 为wss://