Code-server: document usage with nginx

Created on 7 Mar 2019  路  9Comments  路  Source: cdr/code-server

  • code-server version: 1.31.1-100
  • OS Version: Debian 9

I have set up code-server on my server, and now I would like to access it externally. So I have set up a reverse proxy using Nginx. However when I navigate to the url I get an error in Chrome telling me that the page keeps redirecting (ERR_TOO_MANY_REDIRECTS).

If I shut down the code-server and go to the url I just get an error message, so this is correct.

server {
        listen 80;
        listen 443 ssl;
        ssl_certificate /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key /etc/nginx/ssl/nginx.key;

        server_name ide.server.com; # Removed real url

        location ~ ^/ {
                proxy_pass http://localhost:8443;
                proxy_set_header Host             $host;
                proxy_set_header X-Real-IP        $remote_addr;
                proxy_read_timeout 1800;
                proxy_connect_timeout 1800;

                auth_basic "Restricted";
                auth_basic_user_file /etc/nginx/.htpasswd;
        }
}
docs

Most helpful comment

After hours trying, finally this config works for me. code-server v 3.1.0 at ubuntu 16

server {
    listen 80;

    server_name <my-server-name>;

    location / {
        proxy_pass http://localhost:8080;

        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;
    }   
}

All 9 comments

Not too sure what happens to yours but....
Heres my nginx proxy script, it works...

server {
    listen 80;
    listen [::]:80;
    server_name something.something.com;
    location ~/ {
       proxy_pass http://localhost:8443;
       # Set WebSocket Proxy
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection upgrade;
    }
}

Should we add a guide for this?

@kylecarbs might be helpful

I was getting the same error trying to expose code-server with SSL using Traefik reverse proxy.

Make sure to pass --allow-http as option.

Above was merged. Requesting close @nhooyr

For posterity, the appropriate nginx docs are at http://nginx.org/en/docs/http/websocket.html

May I suggest adding a link to the document added in #172 in the main README?

@code-asher can you make this manual again? After update code-server i already get ERR_TOO_MANY_REDIRECTS

After hours trying, finally this config works for me. code-server v 3.1.0 at ubuntu 16

server {
    listen 80;

    server_name <my-server-name>;

    location / {
        proxy_pass http://localhost:8080;

        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;
    }   
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

chrischabot picture chrischabot  路  3Comments

broady picture broady  路  3Comments

tecosaur picture tecosaur  路  3Comments

rcarmo picture rcarmo  路  3Comments

Arsaev picture Arsaev  路  3Comments