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 -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: //

# Use the wget command to download directly in the background under Linux
wget -bc -t 20

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

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 --port 8080 --auth password
# Background process
nohup ./code-server --host --port 8080 --auth password &

Check whether the program port is listening:

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


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;

        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_redirect off;
              proxy_set_header Hosthost;
              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! !


Leave a Reply

Your email address will not be published.