環境:Centos
配置:4h2g(嘗試過 2h2g,就不卡了)
安裝#
curl -fsSL https://code-server.dev/install.sh | sh
sudo systemctl enable --now code-server@$USER
外部訪問#
- 安裝 Nginx
- 開放對應的端口
- 修改 Nginx 配置文件:
server {
listen 111;
server_name 222.222.222.222;
location / {
proxy_pass http://127.0.0.1:222;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
- 111 改為外部訪問接口
- 222.222.222.222 改為伺服器 ip
- :222 改為 code-server 伺服器內部接口
這樣就可以在任何地方,任何設備進行編碼,並且不會因為設備變換改變環境和編程參數。
並且命令都是執行在伺服器上,可以無需考慮多設備配置環境問題。