Code-server: Login redirect does not work with Nginx named locations

Created on 4 Aug 2019  Â·  7Comments  Â·  Source: cdr/code-server

Versions

  • code-server version: code-server1.1156-vsc1.33.1-linux-x64.tar.gz
  • OS Version: Ubuntu 18.04.2 LTS

Description

code-server works fine with Nginx with location set as "location /". However, when location is set to "location /vscode/" code-server fails to properly redirect to the password entry page. It redirects me to <IPv4 Public IP>/login/ which contains 404 Not Found nginx/1.14.0 (Ubuntu). Location "location /vscode/" works fine when code-server -N flag is included. Is there additional arguments I can give Nginx that can help it redirect?

Steps to Reproduce

  1. SSH into EC2 instance

  2. Install Nginx and set configuration as follows

# Server configuration
#
server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name _;

    location /vscode/ {
        proxy_pass http://localhost:1500/;
        rewrite ^/vscode/(.)$ /$1 break;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection upgrade;
        proxy_redirect http://localhost:1500 https://<IPv4 Public IP>;
    }
}
  1. Download code-server stable and run
    ./server/code-server -p 1500 -H

  2. Go to web address
    <IPv4 Public IP>/vscode/
    example
    12.345.67.891/vscode/

bug

Most helpful comment

It appears this login redirect is still an issue on the current release [1.1156-vsc1.33.1] but have found a _workaround_ when using NGINX and the following _proxy_redirect_ configurations in a location, eg:

location /vscode/ {
    proxy_pass https://localhost:8443/;
    rewrite ^/vscode/(.)$ /$1 break;
    proxy_redirect https://localhost:8443/ https://code.example.com/vscode/;
    proxy_redirect ~^/(.*)$ https://code.example.com/vscode/$1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header Accept-Encoding gzip;
}

The _first directive_ rewrites _localhost_ redirects while the _second directive_ rewrites redirects with _absolute paths_ which catches the redirects to "/login" and then "/login/" correctly for me!

Hope this helps out someone else until the next release!

All 7 comments

We're already fixing this on #857. If you want to please help us test the upcoming changes.

I would love to... How do I do that?

I made some LKGR Builds which should allow you to test daily builds of the web branch. Check that out if you don't want to build from source.

Duplicate of #241.

It appears this login redirect is still an issue on the current release [1.1156-vsc1.33.1] but have found a _workaround_ when using NGINX and the following _proxy_redirect_ configurations in a location, eg:

location /vscode/ {
    proxy_pass https://localhost:8443/;
    rewrite ^/vscode/(.)$ /$1 break;
    proxy_redirect https://localhost:8443/ https://code.example.com/vscode/;
    proxy_redirect ~^/(.*)$ https://code.example.com/vscode/$1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header Accept-Encoding gzip;
}

The _first directive_ rewrites _localhost_ redirects while the _second directive_ rewrites redirects with _absolute paths_ which catches the redirects to "/login" and then "/login/" correctly for me!

Hope this helps out someone else until the next release!

Are you using code-server v2? I believe this was fixed in v2.

On Thu, Dec 12, 2019 at 12:05 AM projx notifications@github.com wrote:

Looks like this is still occurring. When running nginx under http:///cs/
the login always redirects to http:///login. This is occuring using the
template provided in the self-hosted quickstart:
https://github.com/cdr/code-server/blob/master/doc/quickstart.md

—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/cdr/code-server/issues/884?email_source=notifications&email_token=ACVYSVD4DOCWBEC6AOTJPYLQYF54ZA5CNFSM4IJEDJK2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEGU75MA#issuecomment-564788912,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ACVYSVFAON4HIYYUAHSHD33QYF54ZANCNFSM4IJEDJKQ
.

Hi all,
Per latest version 2.1698-vsc1.41.1, the below setting works as expected by passing --base-path argument (fixed #241).

Here is the setting hope it is useful for people encountered same issue.

  1. Nginx conf
location /vscode/ {
      proxy_set_header Host $host;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection upgrade;
      proxy_set_header Accept-Encoding gzip;

      proxy_pass http://localhost:8441/;
  }
  1. Code-server execution command:
./code-server --port 8441 --auth password --base-path /vscode
Was this page helpful?
0 / 5 - 0 ratings

Related issues

RealSlimMahdi picture RealSlimMahdi  Â·  3Comments

tecosaur picture tecosaur  Â·  3Comments

pchecinski picture pchecinski  Â·  3Comments

nol166 picture nol166  Â·  3Comments

rcarmo picture rcarmo  Â·  3Comments