Code-Server

Code-Server #

在云主机上运行VS Code,并通过浏览器在任意位置访问它。

codeserver.png

安装 #

  • 操作系统: Ubuntu 24.04
1curl -fOL https://github.com/coder/code-server/releases/download/v$VERSION/code-server_${VERSION}_amd64.deb
2sudo dpkg -i code-server_${VERSION}_amd64.deb
3sudo systemctl enable --now code-server@$USER

更新 #

1sudo dpkg -i code-server_${VERSION}_amd64.deb
2sudo systemctl restart code-server@$USER

配置 #

~/.config/code-server/config.yaml:

1bind-addr: <ip>:<port>
2auth: password
3hashed-password: "<the hashedpassword>"
4cert: false
5disable-telemetry: true
6disable-workspace-trust: true
7app-name: CodeServer

其中hashed-password的生成方式如下:

1sudo apt install argon2
2echo -n "thisismypassword" | argon2 saltItWithSalt  -e

访问 #

http://<ip>:<port>辅以nginx以https://domain-name的形式暴露出来。

  • 在macOS, Windows上的Chrome浏览器中将其安装为PWA应用
  • iPadOS上的Safari浏览器中将其安装为PWA应用

随时随地访问即可。

终端和主题 #

code-server内置终端的字体配置,在settings.json中:

1{
2    "terminal.integrated.fontFamily": "'MesloLGS NF'",
3    "terminal.integrated.fontSize": 15,
4}

iPadOS上使用自定义字体 #

上面的终端方案在ipadOS上存在字体问题,解决这个问题参考了下面两个issue:

最终在nginx上使用ngx_http_sub_module模块的sub_filter插入专门用于iPadOS的字体解决。nginx的配置示例如下:

 1    location / {
 2        proxy_pass   http://<ip>:<port>;
 3        proxy_http_version 1.1;
 4        proxy_set_header   Host             $http_host;
 5        proxy_set_header   X-Real-IP        $remote_addr;
 6        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
 7        proxy_set_header   X-Forwarded-Proto https;
 8        proxy_set_header   Upgrade $http_upgrade;
 9        proxy_set_header   Connection "upgrade";
10        # proxy_set_header Accept-Encoding gzip;
11        proxy_set_header Accept-Encoding "";
12        proxy_redirect off;
13        sub_filter
14        'workbench.web.main.css">'
15        'workbench.web.main.css">
16            <link rel="stylesheet" type="text/css" href="/ios-fonts/css/fonts.css">';
17        sub_filter_once on;
18    }
19
20    location /ios-fonts {
21        autoindex on;
22        alias /opt/code-server/ios-fonts;
23    }

参考链接 #

© 2024 青蛙小白
comments powered by Disqus