Skip to main content Code-Server behind Nginx reverse proxy : r/codeserver
r/codeserver icon
Go to codeserver
•

Code-Server behind Nginx reverse proxy

Hey there,

I have code-server running on a self-hosted machine at home. In LAN it works flawlessly and it's seriously a great piece of software...

I'd like to access my code-server from the internet as well, so I played around with Nginx. I got it working a bit - meaning I get to the login screen, but as soon as I enter my password it reloads a blank page. It does load a monaco-aria-container which contains two emtpy divs (monaco-alert & monaco-status).

I found some pointers to a quickstart.md from code-server, but my google-fu is weak. I can`t find any information on this.

Do you guys have any help on this?

My current Nginx config is as follows:

server {

listen 80;

server_name dev.mycooldomain.com;

location / {

proxy_pass http://localhost:8080;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection upgrade;

}

}

I got this from a github issue - but the behavior doesn't change.

I appreciate any help and thanks a lot in advance!

edit: fixed code block

Sort by:
Best
Open comment sort options

Nevermind - got it to work. The problem was not Nginx, but my code-server.service. I used 0.0.0.0 as Ip - changed that to 127.0.0.1 and it works...

Now onto getting SSL to work :-)

[deleted]
•

I created a script:
https://github.com/equitania/myodoo-docker/blob/master/nginx-conf/create_code-server_ssl.sh

and a template
https://github.com/equitania/myodoo-docker/blob/master/nginx-conf/code-server_template.conf

That will you create a nginx conf file with ssl optional Let's encrypt.

Code-Server als Service
$ nano /usr/bin/code-server.sh
export PASSWORD="yourpassword"
code-server /home/devops/ --user-data-dir=/home/devops/vscode  --port=9000

$ chmod +x /usr/bin/code-server.sh
$ nano /lib/systemd/system/code-server.service
..
[Unit]
Description= Visual Studio Code Server.
[Service]
Type=simple
User=devops
ExecStart=/bin/bash /usr/bin/code-server.sh
Restart=always
KillSignal=SIGQUIT
[Install]
WantedBy=multi-user.target
..

$ sudo systemctl daemon-reload
$ sudo systemctl start code-server.service
$ sudo systemctl enable code-server.service

[deleted]
• • Edited

I've been messing around with this today in an attempt to get a secure connection to my local server.

I've installed code-server as a docker container running on port 8443 and wanted to get rid of the insecure message. I run a Nginx server as a reverse proxy on the same machine.

Here is the appropriate snippet from my Nginx config:

location /code-server/ {

proxy_pass http://127.0.0.1:8443/;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_set_header X-NginX-Proxy true;

proxy_http_version 1.1;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_redirect off;

}

https://my.domain/code-server/ now works.

Some of the headers may be redundant but the above works for me.

The thing that finally made this work was the trailing "/" on the location.

got truly inspired by this answer. before seeing it, I thought the only way to reverse-proxy /code-server is by setting the context url for vscode to be /code-server. never thought the trailing slash would solve it! truly thankful!!!

I have similar setup to yourself, code server as Docker container and LetsEncrypt for SSL handing. Code server is working except I'm unable to clone a github repo based on user name / password. I get "Oh no! An error occurred!" / forbidden message when trying to use git extension to obtain github authorisation.

Are you able to sign in to github with your code server / nginx setup?

Addiionally I've tried using a github generated token but that also fails, but with error relating to incorrect format.

Thanks to the hint above, if anyone needs to make Traefik work, here are the two middlewares I'm using on mine. The code-redirect adds the trailing slash, and the code-stripprefix... strips the prefix.

traefik.http.routers.code.middlewares=code-redirect, code-stripprefix
traefik.http.middlewares.code-redirect.redirectregex.regex=^(.*)/code$$
traefik.http.middlewares.code-redirect.redirectregex.replacement=$${1}/code/
traefik.http.middlewares.code-stripprefix.stripprefix.prefixes=/code/

I have been looking for hours, it now works, I was missing those headers:

proxy_set_header X-NginX-Proxy true;

proxy_redirect off;

More replies