Skip to content

Can't use when I set sub url reverse-proxy  #1608

Closed

Description

@deadcatssociety

Hello, First, sorry for my english skill.

I use Traefik for reverse proxy.
I want to use code-server domain like https://<mydomain>/vscode <-> docker code-server

but when I set subdomain to code-server, always show me error page by traefik (401 error)
I think it occured by redirecting to login page

When I test same option and change code-server running into root domain(https://<mydomain>), It works, but when I use subdomain(https://<mydomain>/vscode), It broken.

My code server version is 3.2.0 + linux-server's docker image

I don't know it is traefik setting issue or code-server issue exactly.
Please help

my docker swarm compose file is:

version: "3.3"
services:
  vscode:
    image: linuxserver/code-server:latest
    environment:
      - PUID=1004
      - PGID=1004
      - TZ=Asia/Seoul
      - PASSWORD=<PASSWORD>
      - SUDO_PASSWORD=<PASSWORD>
    volumes:
      - /home/swarm/vscode/config:/home/coder/.local/share/code-server
      - /home/swarm/vscode/workspace:/home/coder/project
    networks:
      - traefik
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.hostname == <INSTANCE NAME>
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.vscode.rule=Host(`<DOMAIN NAME>`) && PathPrefix(`/vscode`)"
        - "traefik.http.routers.vscode.entrypoints=websecure"
        - "traefik.http.services.vscode.loadbalancer.server.port=8443"

networks:
  traefik:
    external: true

Activity

  1. code-asher commented on May 8, 2020

    @code-asher
    Member

    code-server expects the reverse proxy to rewrite the URL so /vscode becomes /. I'm not familiar with Traefik so I'm not sure exactly how that's done but it looks like there's a PathPrefixStrip you can use.

    The second thing is to make sure you browse to the page with a trailing slash, i.e. https://<mydomain>/vscode/. This is because code-server uses relative URLs like ./static/... and if there's no trailing slash they'll go against the root instead of the sub-path.

  2. deadcatssociety commented on May 9, 2020

    @deadcatssociety
    Author

    PathPrefixStrip removed since traefik 1.4, current version is 2.2.

    it's not work. I think something I set wrong config. (or not work with url sub path)
    I will check traefik's document and forum.

    Thanks for your advice!

  3. deadcatssociety commented on May 12, 2020

    @deadcatssociety
    Author

    I fix the problem.
    someone like me, use this settings:

            - "traefik.enable=true"
            - "traefik.http.routers.vscode.rule=Host(`$DOMAIN`) && PathPrefix(`/vscode`)"
            - "traefik.http.routers.vscode.middlewares=vscode-stripprefix"
            - "traefik.http.middlewares.vscode-stripprefix.stripprefix.prefixes=/vscode"
            - "traefik.http.routers.vscode.entrypoints=websecure"
            - "traefik.http.services.vscode.loadbalancer.server.port=8443"

    important point is stripprefix

    thanks code-asher you give inspiration to me :D

  4. code-asher commented on May 12, 2020

    @code-asher
    Member

    Awesome, I'm glad you got it sorted!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions