Deploy online code-server code editor under Linux

code-server is a web-based code editor for vs-code running on the server. Its extensible plugins are very wide and can be used Python, c/c++, jave, shell, html, css and other mainstream languages ​​are very powerful

Let’s explain how to deploy code-server on a Linux-based server

Check the effect animation first:

One, docker deployment

If your server has the docker program installed, directly execute the following command:

# docker execution
docker run -it -p 127.0.0.1:8080:8080 -v "$PWD:/home/coder/project" codercom/code-server

But docker runs, it may run a bit slow, affect the experience, the following describes the binary code to run directly to improve the running speed

Two, binary code deployment

1. Get the executable code of code-server

Official website link: https: //github.com/cdr/code-server/releases

# Use the wget command to download directly in the background under Linux
wget -bc -t 20 https://github.com/cdr/code-server/releases/download/3.2.0/code-server-3.2.0-linux-x86_64.tar.gz

GitHub is abroad, download is very slow, local cache greatly improves download speed

Local download: code-server

# Use the wget command to download directly in the background under Linux
wget -bc -t 20 https://www.ivdone.top/wordpress/pic/p662/code-server-3.2.0-linux-x86_64.tar.gz

2. Unzip

# Unzip with the tar command
tar -zxvf code-server-3.2.0-linux-x86_64.tar.gz
# Enter the directory
cd code-server-3.2.0-linux-x86_64/

3. Set web login password

# Edit ~/.bashrc file
vi ~/.bashrc
# Export the environment variables at the end of the file, xxxxxx is the login password you set yourself, save
export PASSWORD="xxxxxx"
# Update environment variables
source ~/.bashrc

4. Run

# Check whether the port is occupied, pay attention to the Linux firewall to open the port
lsof -i:8080
# The foreground is running, the login password is enabled
./code-server --host 0.0.0.0 --port 8080 --auth password
# Background process
nohup ./code-server --host 0.0.0.0 --port 8080 --auth password &

Check whether the program port is listening:

# View program network monitoring status
netstat -nlp | grep 8080

Effect:

5. Configure nginx

If the machine does not have Nginx installed, please move to my blog link->Linux installation Nginx tutorial< /a>

where “xxx” is configured according to your needs

http {
    include mime.types;
    default_type application/octet-stream;
sendfile on;
server {
        listen 80;
        server_name 192.168.8.160;

        proxy_set_header X-Forwarded-For $remote_addr;
location / {
            index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
}
# vs-code
        location /xxx {# Or / if hosting at the root.
              rewrite ^/xxx/(.*)$ /$1 break;
              proxy_pass http://127.0.0.1:8080/;
              #proxy_redirect off;
              proxy_set_header Host $host;
              proxy_set_header Upgrade $http_upgrade;
              proxy_set_header Connection upgrade;
              proxy_set_header Accept-Encoding gzip;
        }
}
}

Restart nginx:

# Restart
nginx -s reload

6. Test

Access method: http://ip/xxx/

Success interface:


Congratulations on completing the deployment, please enjoy! !

0

Leave a Reply

Your email address will not be published.