novnc 通过websockify代理 配置多点访问


没有图形界面需要先安装图形界面
注意:
如果没有安装 Linux 图形界面,则需要安装:
rpm -qa |grep gnome 【检查是否安装了图形界面】
yum groupinstall "X Window System" "Chinese Support" "Desktop" 【安装】
下载novnc客户端
git clone https://github.com/novnc/noVNC.git
直接启动noVnc
./utils/novnc_proxy --vnc localhost:5901
指定代理端口启动noVnc
./utils/novnc_proxy --vnc localhost:5901 --listen localhost:6081
下载websockify
git clone https://github.com/novnc/websockify.git

 

加密wss(非必须)

要使用 WebSocket 'wss://' URI 方案加密流量,您需要生成证书和密钥以供 Websockify 加载。默认情况下,Websockify 加载证书文件名,self.pem--cert=CERT--key=KEY 选项可以覆盖文件名。您可以使用 openssl 生成自签名证书。当要求提供通用名称时,请使用将运行代理的服务器的主机名:

openssl req -new -x509 -days 365 -nodes -out self.pem -keyout self.pemp

配置websockify下的文件,新建tokenfile vim文件

t1: {your的IP}:5900
t2: {your的IP}:5901
启动websockify
./run -v --token-plugin TokenFile --token-source ./tokenfile localhost:9090
 
配置nginx  
upstream novnc_ws {
        server localhost:9090; //websockify的地址
}

server {
        listen 5800;
        server_name localhost;


        add_header Vary Accept-Encoding;
        add_header X-Whom gzcj-prod-2;
        add_header Cache-Control no-cache;

        client_max_body_size 1024m;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Scheme $scheme;
        proxy_redirect off;

        location / {
                root noVNC;//文件夹所在路径;
                index vnc.html;
        }
        location /websockify {
                proxy_pass http://novnc_ws;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
        }
}

 重启nginx。

检查vncserver是否安装

rpm -qa | grep vnc

如果没有,安装

yum install tigervnc tigervnc-server -y

 

启动服务

vncserver :1

启动5900 + 1

修改密码

vncpasswd

若开启了防火墙,手动开启端口

iptables -I INPUT -p tcp --dport 5902 -j ACCEPT

设置开机启动

chkconfig vncserver on


然后访问这个网址就可以链接虚拟机了 http://{task服务器IP}:5800/?path=websockify%3ftoken=t0{0~1}就可以访问

  

posted @ 2021-12-08 11:06  啦啦拉扎尔  阅读(2053)  评论(0编辑  收藏  举报