theia 安装后的样子:
theia 是一套构建基于 web 的云端工具和 IDE 的开源框架。theia 提供了一个工作框架、模块系统、和 git 集成等一些可重用的特性。基于 theia 的工具可以远程部署,并通过浏览器或桌面应用如 Electron 进行访问。theia 基于 Typescript、HTML、CSS、LSP(Language Server Protocol)和 VS Code 提供的 Monaco 代码编辑器构建。
它是一套开源框架,而不是一个最终产品,开发者可以基于 theia 构建和自定义一款属于自己的 IDE 或工具,例如 gitpod、建模工具等。
有如下几种方式:
本文介绍第 1 种方式,即通过源码安装。
为了提高安装速速,并且避免网络错误,可在腾讯云硅谷买一台 CVM,操作系统为 ubuntu 18。
安装 node 10 和 yarn:
wget https://nodejs.org/dist/latest-v10.x/node-v10.22.0-linux-x64.tar.gz
tar zxvf node-v10.21.0-linux-x64.tar.gz -C /usr/local
echo "export PATH=/usr/local/node-v10.21.0-linux-x64/bin:$PATH" >> /etc/profile
echo "export PATH=/usr/local/node-v10.21.0-linux-x64/bin:$PATH" >> /etc/bash.bashrc
source /etc/profile
npm install -g yarn
theia 前置安装:
apt-get install -y g++ gcc make
apt-get install -y pkg-config
apt-get install -y build-essential
apt-get install -y libx11-dev libxkbfile-dev
apt-get install -y git
安装 theia
git clone https://github.com/eclipse-theia/theia
cd theia
yarn
cd examples/browser
yarn run start --hostname 0.0.0.0 --port 3000
如果安全组开放了 3000 端口,此时便可以通过 http://IP:3000 访问了。
theia 没有登录认证功能,任何人都可以访问,不安全,可借助 ngx_http_auth_digest 模块进行登录认证。
下载 ngx_http_auth_digest:
wget https://github.com/atomx/nginx-http-auth-digest/archive/v1.0.0.tar.gz
tar zxvf v1.0.0.tar.gz
编译安装 nginx 时,加上参数:
--add-module=nginx-http-auth-digest的路径
生成登录密码:
apt-get install -y apache2-utils
htdigest -c /usr/local/passwd.digest theia admin
其中
在 nginx 配置文件中添加 server 段:
server {
listen 80 default_server;
auth_digest_user_file /usr/local/passwd.digest;
auth_digest_shm_size 8m; # the storage space allocated for tracking active sessions
location / {
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
auth_digest 'theia';
auth_digest_timeout 60s; # allow users to wait 1 minute between receiving the
# challenge and hitting send in the browser dialog box
auth_digest_expires 600s; # after a successful challenge/response, let the client
# continue to use the same nonce for additional requests
# for 600 seconds before generating a new challenge
auth_digest_replays 60; # also generate a new challenge if the client uses the
# same nonce more than 60 times before the expire time limit
proxy_pass http://127.0.0.1:3000;
}
}
其中,
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
这两行必须有,否则不能正确代理 websocket。这个配置相当于每 (auth_digest_timeout+auth_digest_expires)=660s 允许 auth_digest_shm_size/((48 + ceil(auth_digest_replays/8))bytes)=(8*1024*1024)/(48+8)=149.8k 次请求,即每 660s 允许约 149.8k 次请求。登录认证 10min 后过期。
最后启动 nginx,会弹出登录认证框,输入用户名和密码后即可登录,跳转到 theia 界面。
为了更加安全,需要先停掉 theia,将启动方式
yarn run start --hostname 0.0.0.0 --port 3000
改为:
yarn start
默认监听端口为 3000。
https://github.com/eclipse-theia/theia/blob/master/doc/Developing.md#quick-start
https://www.nginx.com/resources/wiki/modules/auth_digest
https://www.yangyang.cloud/blog/2015/07/17/session-with-express-and-nginx
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。