最後更新: 2024-05-07
前言
目錄
- 安裝
- websockify
- nginx
安裝
novnc = html, js 檔
websockify = 負責 Browner 與 VNC 之間的通訊
apt-get install novnc websockify
Notes
- 建議在 Github 下載 noVNC 的 source code 因為 U22 的 version 係 1.0
websockify
websockify just translates WebSockets traffic to normal TCP socket traffic.
websockify was formerly named wsproxy and was part of the noVNC project.
Usage
確定 novnc 的 Folder
ls -1 /usr/share/novnc
app core include utils vendor vnc.html vnc_auto.html # vnc_lite.html # 直接入 pw
Syntax
websockify [options] [source_addr:]source_port [target_addr:target_port]
# 基本
websockify --web=/usr/share/novnc 8080 localhost:5900
VNC Client
http://URL:8080/vnc.html
# -D, --daemon
websockify -D --web=/usr/share/novnc localhost:5900
# SSL 版
websockify -D --cert=/home/ubuntu/novnc.pem --web=/usr/share/novnc 8080 localhost:5901
Service Config
useradd -d /usr/share/novnc -s /bin/false novnc
/etc/systemd/system/novnc-user1.service
[Unit] Description=NoVNC Service 1 After=network-online.target [Service] ExecStart=websockify --web=/usr/share/novnc 8080 localhost:5900 User=novnc Group=novnc Restart=always RestartSec=3 [Install] WantedBy=default.target
systemctl enable novnc-user1 --now
lsof -i tcp:8081
nginx
server { listen 80 default_server; #add_header Cache-Control no-cache; #listen 9001 ssl default_server; #ssl_certificate ssl/DOMAIN/server.pem; #ssl_certificate_key ssl/DOMAIN/server.key; root /var/www/html; index index.html index.htm; server_name _; location ~ /\.ht { deny all;} # NoVNC Settings location / { auth_basic "Restricted"; auth_basic_user_file htpasswd.txt; #add_header Cache-Control no-cache; proxy_pass http://127.0.0.1:8081/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_read_timeout 7200; } }
優化
# Cache Folder # mkdir /var/lib/nginx/cache # chown www-data: /var/lib/nginx/cache proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=MyCache:10m inactive=7d max_size=1g; server { location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ { expires 1w; log_not_found off; proxy_pass http://127.0.0.1:8081; proxy_cache MyCache; proxy_cache_valid 200 7d; add_header X-Cache-Status $upstream_cache_status; } ... }