ttyd+nginx 比gotty更加优秀的搭配

in 日常前后端开发 with 0 comment

首先我们需要知道,ttyd相对于gotty有哪些优势?

比较项gottyttyd
语言GOC
支持USD
(Unix Domain Socket)
不支持支持
终端优化优秀不错

但是这个项目的前端写死了字号颜色等,因此我修改了一下,图标来自于Win11自带的终端

优化后

那么再去看看 知乎上的教程,配合下文食用,美美哒...

+nginx?

强烈建议systemd值守+开unixSocket减小开销(其实code-server也是可以的,延迟不出所料地降低了,咳咳串台了)

如何做

然后也很简单,在你组合好的命令后加上-i /tmp/shell.sock就行了,nginx也可以照搬gotty的配置

location = /@shell/ws {
    proxy_pass                          http://unix:/tmp/shell.sock:/ws;
    proxy_set_header Upgrade            $http_upgrade;
    proxy_set_header Connection         upgrade;
    proxy_set_header Origin             "http://127.0.0.1:10000";
    proxy_set_header Accept-Encoding    '';
    
    set     $auth                       'WebShell 身份认证';
    
    if ( $http_upgrade = '' ) {
        return 404;
    }
    
    if ( $host = '192.168.1.2' ) {
        set $auth                       off;
    }
    
    auth_basic                          $auth;
    auth_basic_user_file                /etc/nginx/sites-authconfig/shell.list;
    
    set         $limit_rate             1k;
}

location /@shell/ {
    alias                               /www/static/webshell/;
    
    if ( $host != '192.168.1.2' ) {
        set $auth 'Basic realm="WebShell 身份预验证"';
    }
    add_header      'Www-Authenticate'  auth;
}

优化

然后再在/www/static/webshell里放上我们的 调味包 优化后的文件
完美~~~

(其实自己改很方便的,不过我修改后已经可以自定义了就不手把手教学了)

修改

Responses