Code-server: Cannot get server to work with Ngnix.

Created on 1 Nov 2019  路  14Comments  路  Source: cdr/code-server

Description

I have Ngnix server setup on a DigitalOcean droplet with let's encrypt SSL.
When I open up the site, I get the 'welcome to ngnix' page.
When I try to run code-server from the cmd line I get: (I replaced website name)
sudo /usr/bin/code-server --host 0.0.0.0 --cert /etc/letsencrypt/live/my.website.com/fullchain.pem --cert-key /etc/letsencrypt/live/my.website.com/privkey.pems
info Server listening on https://0.0.0.0:8080
info - Password is ....
info - To use your own password, set the PASSWORD environment variable
info - To disable use --auth none
info - Using provided certificate and key for HTTPS

When I go to https://my.website.com, I still have the same 'welcome to Ngnix' page.

How do I get this to work?

question

Most helpful comment

I finally got the systemd to work, although it's still on root user and not my user. Here's the file I got to work for others to ref:
[Unit]
Description=Code Server IDE
After=network.target

[Service]
Restart=on-failure
Type= simple
RestartSec=10
ExecStop=/sbin/start-stop-daemon --stop -x /usr/bin/code-server
StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

User=erick
Group=erick

WorkingDirectory=/code/
Environment="PASSWORD=MY_AMAZING_PASSWORD!"
ExecStart=/usr/bin/code-server --port 8080 --host 127.0.0.1

[Install]
WantedBy=multi-user.target

Thanks for your help!!

All 14 comments

Have you set up Nginx to point to code-server? Something like this: https://github.com/cdr/code-server/blob/master/doc/quickstart.md#nginx-reverse-proxy

BTW if you're running Nginx on the same server you don't need to listen on 0.0.0.0. The default (127.0.0.1) will be more secure.

Oh also I'd recommend you handle SSL termination in Nginx instead of code-server since you have Nginx anyway. That'll look something like:

server {
  listen 443 ssl;
  server_name my.website.com;
  ssl_certificate     /etc/letsencrypt/live/my.website.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/my.website.com/privkey.pem;
  ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers         HIGH:!aNULL:!MD5;
  location / {
      proxy_pass http://localhost:8080/;
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;
  }
}

Thanks for getting back to me so quickly.

A good portion of that was already in place from let's encrypt. I added the rest, but I'm still not getting the code server.
Here's /etc/ngnix/site-enabled/default

server {
 server_name my.website.com; # managed by Certbot
        listen [::]:443 ssl ipv6only=on; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/my.website.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/my.website.com/privkey.pem; # managed by Certbot
        include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
        location / {
                proxy_pass http://localhost:8080/;
                proxy_set_header Host $host;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection upgrade;
                proxy_set_header Accept-Encoding gzip;
                }
}
server {
    if ($host = my.website.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80 ;
        listen [::]:80 ;
    server_name my.website.com;
    return 404; # managed by Certbot
}

I then ran this:

$ sudo /usr/bin/code-server --port 8080 --host 127.0.0.1 
info  Server listening on http://127.0.0.1:8080
info    - Password is 34bafd49e7e77bde8ef903f5
info      - To use your own password, set the PASSWORD environment variable
info      - To disable use `--auth none`
info    - Not serving HTTPS

Still just getting the default ngnix page.

Thoughts? Suggestions?

Also, I have set the env PASSWORD, but it doesn't seem to see it.

Okay, I uninstalled/re-installed nginx and got it working. YAY!
Just a few things to clean up:

  • I tried setting up a systemd configuration and it keeps failing. I've looked at all the examples I could find on here, and I still have no luck.
  • The default user on launching is root. I opened the terminal and it had root@code-server listed.
  • It still won't recognize the env PASSWORD. I set it per the export instructions. Where else can I set that up?
  • Is there a way to set things up so that a user logs in rather than just a password?
  • Lastly, is there any way to set the favorite (browser tab) icon?

Cheers!

Closing as resolved

As for password, can you try it like this?

PASSWORD="uwu" ./code-server [flags]

@sr229 that worked for the password. I'm still unable to get the systemd process to work. I've followed the example in the repo and I still cannot get it to work. I keep getting an Exec format error. Thoughts?

Currently there are no other supported authentication method but we're tracking logging in as a user on the system here: https://github.com/cdr/code-server/issues/64

code-server doesn't have a built-in way to change the favicon but you could use nginx to route the favicon request to your own file.

For the default user, setting User in the systemd file should work. I'm not sure about the exec error though. Are you able to run the exact same binary systemd is trying to spawn? I think I've seen that error when running a binary compiled for a different platform. Or maybe the path in the systemd file to the code-server binary is incorrect.

On the systemd error, I finally found the error message:
Executable path is not absolute

I have code-server setup at /usr/bin/code-server. What would the absolute path be for that?

I finally got the systemd to work, although it's still on root user and not my user. Here's the file I got to work for others to ref:
[Unit]
Description=Code Server IDE
After=network.target

[Service]
Restart=on-failure
Type= simple
RestartSec=10
ExecStop=/sbin/start-stop-daemon --stop -x /usr/bin/code-server
StandardOutput=file:/var/log/code-server-output.log
StandardError=file:/var/log/code-server-error.log

User=erick
Group=erick

WorkingDirectory=/code/
Environment="PASSWORD=MY_AMAZING_PASSWORD!"
ExecStart=/usr/bin/code-server --port 8080 --host 127.0.0.1

[Install]
WantedBy=multi-user.target

Thanks for your help!!

Oh, I have one last question - is it possible to remote into the server with VS Code on a computer using SSH?

Are you wanting to SSH to a machine that is already running code-server?
We're working on allowing SSH through code-server here:
https://github.com/cdr/code-server/pull/1139

If you already have SSH access and you want to run code-server on the
remote machine you could look at sshcode: https://github.com/cdr/sshcode

If you want to use code-server on a remote machine to edit another
remote machine using something like the SSH vscode-remote extension then
I don't believe that's currently possible. You'd have to just deploy
code-server on the second machine (possibly using sshcode).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oonqt picture oonqt  路  3Comments

RealSlimMahdi picture RealSlimMahdi  路  3Comments

balazssoltesz picture balazssoltesz  路  3Comments

tecosaur picture tecosaur  路  3Comments

pchecinski picture pchecinski  路  3Comments