💻

代码服务器

开发工具

VS Code 在浏览器中运行,可随时随地进行远程开发。

部署信息

部署: 2-5分钟
类别: 开发工具
最小内存: 1024MB
支持: 入票和电子邮件

共享此指南

概览

code-server 是在浏览器中运行的 VS Code,让您无论使用哪种设备,只要有 Web 浏览器,就能使用微软广受欢迎的桌面 IDE 的全部功能。该项目由 Coder 开发和维护,让您可以在平板电脑、Chromebook 或任何计算机上编写、调试和部署代码,而开发环境则运行在强大的远程服务器上。

code-server 的妙处在于,它提供与您熟悉的 VS Code 完全相同的体验,只是通过 Web 浏览器访问。所有功能一应俱全:IntelliSense 代码补全、调试、集成终端、Git 集成、拥有数千个插件的扩展市场,以及熟悉的界面。唯一的区别是您通过 HTTPS 访问,而不是在本地运行,但编辑体验依然流畅、响应迅速。

将开发环境运行在服务器上优势明显。整个团队可获得一致、可复现的环境,彻底告别“在我机器上能跑”的问题。与本地笔记本相比,强大的服务器硬件可加快编译、测试和构建速度。您的代码和开发状态可随时从任何设备访问,非常适合远程办公、在设备之间切换,或结对编程。

安全和隐私是 code-server 设计中内置的。浏览器与服务器之间的所有通信均经过 TLS/SSL 加密。密码认证以及通过反向代理提供的可选 OAuth2 保护你的开发环境访问。除非你明确推送到版本控制系统,否则代码永远不会离开服务器,因此它非常适合处理敏感代码库,或满足禁止代码存放在本地设备上的安全合规要求。

code-server 非常适合云端开发工作流。将其部署在性能强劲、网络快速的云实例上,即可获得即时的代码同步、快速的软件包安装,并可从集成终端通过 SSH 连接到生产服务器。内置端口转发功能可直接在浏览器中预览 Web 应用,并自动提供 HTTPS 和身份验证。您还可以处理大型代码库,而无需担心本地磁盘空间或内存限制。

扩展生态非常丰富,大多数 VS Code 扩展都能与 code-server 无缝配合。语言支持、代码检查工具、格式化工具、主题和生产力工具均可使用。你可以通过挂载 VS Code 配置目录,在多个实例之间同步设置和扩展。部分扩展可能需要少量修改,但核心市场提供了数千个可直接使用的扩展。

无论您是在咖啡馆工作的自由开发者、需要统一开发环境的远程团队、在线教授编程的教育工作者,还是需要落实零信任安全策略的企业,code-server 都能提供专业级开发工具,随时随地访问,且不影响功能与性能。

密钥特征

浏览器中的完整 VS Code

具备全部功能的完整 VS Code 体验,包括 IntelliSense、调试、扩展、主题和集成终端

随时随地办公

只要有浏览器,任何设备都能访问您的开发环境,包括平板电脑、Chromebook 或任何计算机

强大的远程开发

借助服务器硬件进行编译、测试和构建,同时在浏览器中流畅编辑代码

广泛的扩展支持

可使用数千个 VS Code 扩展,包括语言服务器、代码检查工具、格式化工具和生产力工具

默认安全

TLS 加密、密码认证、通过反向代理可选的 OAuth2,以及代码留在服务器上以满足合规要求

内置端口转发

通过 code-server 的隧道功能,自动提供 HTTPS 和身份验证,即可预览 Web 应用

使用案例

• 远程开发团队:为分布式团队提供一致的开发环境,即刻完成设置
• 云原生开发:直接在靠近生产环境的云服务器上构建和测试云应用
• 教育与培训:通过浏览器链接即可访问预先配置好的环境,轻松教授编程
• 合同与咨询工作:安全访问客户代码库,无需下载到个人设备
• 移动开发:在 iPad 或平板电脑上使用完整 IDE 进行编码,适合出差或通勤途中的开发工作
• 高性能计算:利用强大的云实例处理大型代码库、AI/ML 或编译密集型项目
• 零信任安全:满足要求代码必须留在企业基础设施内的政策规定

《安装指南》

在 Ubuntu 22.04 LTS 上安装:

1. 通过安装脚本安装(推荐):
curl -fsSL https://code-server.dev/install.sh | sh
2. 或手动安装:
# Download latest release
VERSION=$(curl -s https://api.github.com/repos/coder/code-server/releases/latest | grep -oP '"tag_name": "v\K[^"]+')
wget https://github.com/coder/code-server/releases/download/v${VERSION}/code-server_${VERSION}_amd64.deb

# Install package
sudo dpkg -i code-server_${VERSION}_amd64.deb
3. 配置 code-server:
# Edit config file
nano ~/.config/code-server/config.yaml
设置配置:
bind-addr: 0.0.0.0:8080
auth: password
password: your_secure_password_here
cert: false  # We'll use reverse proxy for SSL
4. 创建 systemd 服务:
sudo systemctl enable --now code-server@$USER
sudo systemctl status code-server@$USER
5. 配置 Nginx 反向代理:
sudo apt install nginx -y
sudo nano /etc/nginx/sites-available/code-server
添加配置:
server {
    listen 80;
    server_name code.yourdomain.com;

    location / {
        proxy_pass http://127.0.0.1:8080;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_set_header Accept-Encoding gzip;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}
启用站点:
sudo ln -s /etc/nginx/sites-available/code-server /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
6. 获取 SSL 证书:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d code.yourdomain.com
7. 访问 code-server:
在浏览器中打开 https://code.yourdomain.com
- 使用 config.yaml 中的密码登录

8. 安装扩展:
# Via command line
code-server --install-extension ms-python.python
code-server --install-extension esbenp.prettier-vscode

# Or use Extensions panel in UI
9. 配置防火墙:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 22/tcp  # SSH
10. 可选,安装 Docker:
# Run code-server in Docker
docker run -it --name code-server -p 127.0.0.1:8080:8080 \
    -v "$HOME/.config:/home/coder/.config" \
    -v "$HOME/projects:/home/coder/projects" \
    -u "$(id -u):$(id -g)" \
    -e "DOCKER_USER=$USER" \
    codercom/code-server:latest

配置提示

基本配置:

1. 配置文件(~/.config/code-server/config.yaml):
bind-addr: 0.0.0.0:8080
auth: password
password: secure_password_here
cert: false
proxy-domain: code.yourdomain.com
2. 身份验证方式:
# Password authentication (default)
auth: password
password: your_password

# Disable authentication (dangerous, use with reverse proxy auth)
auth: none

# Use hashed password
hashed-password: "$argon2i$v=19$m=4096,t=3,p=1$..."
3. 环境变量:
# Set password via env
export PASSWORD="your_password"

# Disable telemetry
export TELEMETRY_LEVEL="off"

# Custom extensions directory
export EXTENSIONS_GALLERY='{"serviceUrl": "https://open-vsx.org/vscode/gallery"}'
4. 端口转发配置:
# Forward local dev server to public URL
# In code-server terminal:
npm run dev  # Starts on localhost:3000

# code-server automatically detects and offers to forward
# Access at: https://code.yourdomain.com/proxy/3000/
5. 扩展配置:
# Install from marketplace
code-server --install-extension publisher.extension-name

# Install from VSIX
code-server --install-extension /path/to/extension.vsix

# List installed extensions
code-server --list-extensions

# Uninstall extension
code-server --uninstall-extension publisher.extension-name
6. 设置同步:
// settings.json location: ~/.local/share/code-server/User/settings.json
{
    "workbench.colorTheme": "Default Dark+",
    "editor.fontSize": 14,
    "editor.formatOnSave": true,
    "files.autoSave": "afterDelay",
    "terminal.integrated.shell.linux": "/bin/bash"
}
7. 多用户设置:
# Create service for user1
sudo systemctl enable --now code-server@user1

# Create service for user2  
sudo systemctl enable --now code-server@user2

# Each user gets own config in their home directory
# ~/.config/code-server/config.yaml
8. 安全加固:
# Limit network access
bind-addr: 127.0.0.1:8080  # Only localhost

# Use strong password (20+ chars)
password: $(openssl rand -base64 32)

# Enable HTTPS on reverse proxy
# Use fail2ban for brute force protection
sudo apt install fail2ban

# Configure fail2ban for code-server
sudo nano /etc/fail2ban/jail.local
添加:
[nginx-code-server]
enabled = true
port = 80,443
filter = nginx-code-server
logpath = /var/log/nginx/access.log
maxretry = 3
bantime = 3600
9. 性能调优:
# Increase file watcher limit
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

# Disable telemetry
export TELEMETRY_LEVEL=off

# Use faster protocol
# In settings.json:
{
    "terminal.integrated.rendererType": "dom"
}
10. 备份与迁移:
# Backup user data
tar -czf code-server-backup.tar.gz \
    ~/.local/share/code-server \
    ~/.config/code-server

# Restore on new server
tar -xzf code-server-backup.tar.gz -C ~
最佳实践:
- 使用反向代理(Nginx/Caddy)实现 SSL 终止
- 启用 Let's Encrypt 自动 HTTPS
- 设置高强度密码(20 个以上字符)
- 定期更新 code-server:curl -fsSL https://code-server.dev/install.sh | sh
- 将项目目录单独挂载,便于备份
- 使用 systemd 在故障时自动重启
- 在反向代理上配置速率限制
- 启用 fail2ban 防止暴力破解
- 使用 OAuth2 代理实现 SSO 集成
- 按用户或团队分别部署开发、预发布和生产实例
- 查看日志:journalctl -u code-server@$USER -f
- 设置用户数据和配置的自动备份

技术要求

系统要求

  • 记忆: 1024MB 内存(MM)

请为这篇文章评分

★★★★★
-
正在装入...

准备好部署您的应用程序了吗? 代码服务器?

几分钟后开始 我们简单的VPS部署程序

大约2分钟后部署 • 全部根访问 • 支持 以票和电子邮件方式