VS Code在线编辑器code-serve安装
1、code-server
code-server是一款在线的vscode工具,只要将 code-server 部署到自己的服务器之后,就可以通过浏览器使用vscode,很好的解决了远程编辑服务器中文件的问题,方便好用。
code-server的地址为: https://github.com/cdr/code-server
2、准备
- 准备一台linux机器
- 安装docker:https://docs.docker.com/install/linux/docker-ce/centos/
- 如果要反向代理,安装nginx
3、安装
-
在linux上创建一个目录,用来存放编辑器可以访问的文件例如:
mkdir -p /usr/local/codefolder
-
修改文件夹的权限,否则无法创建和修改文件
chmod -R 777 /usr/local/codefolder
-
安装:
docker run --name codeserver -d -p 8443:8443 -v "/usr/local/codefolder:/home/coder/project" codercom/code-server --allow-http --no-auth
-
浏览器访问http://localhost:8443
4、参数配置详情
sage: code-server [options]
Run VS Code on a remote server.
Options:
-V, --version output the version number
--cert <value>
--cert-key <value>
-e, --extensions-dir <dir> Override the main default path for user extensions.
--extra-extensions-dir [dir] Path to an extra user extension directory (repeatable). (default: [])
--extra-builtin-extensions-dir [dir] Path to an extra built-in extension directory (repeatable). (default: [])
-d, --user-data-dir <dir> Specifies the directory that user data is kept in, useful when running as root.
-h, --host <value> Customize the hostname. (default: "0.0.0.0")
-o, --open Open in the browser on startup.
-p, --port <number> Port to bind on. (default: 8443)
-N, --no-auth Start without requiring authentication.
-H, --allow-http Allow http connections.
--disable-telemetry Disables ALL telemetry.
--socket <value> Listen on a UNIX socket. Host and port will be ignored when set.
--trust-proxy Trust the X-Forwarded-For header, useful when using a reverse proxy.
--install-extension <value> Install an extension by its ID.
-h, --help output usage information
5、Nginx反向代理
配置文件:
#user nobody;
worker_processes 2;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
client_max_body_size 200m;
#gzip on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream websocket {
server localhost:8443;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
}