Skip to content

[Bug]: proxy by nginx websocket origin check error #6161

Closed

Description

@502647092

Is there an existing issue for this?

  • I have searched the existing issues

OS/Web Information

  • Web Browser: EDGE
  • Local OS: Windows
  • Remote OS: Linux
  • Remote Architecture: x64
  • code-server --version: 4.12.0

Steps to Reproduce

  1. start code server by docker
  2. proxy by nginx
  3. open website

Expected

.

Actual

websocket connect error code 1006

Logs

debug host "ide.wsc.ink:443" does not match origin "ide.wsc.ink";

Screenshot/Video

No response

Does this issue happen in VS Code or GitHub Codespaces?

  • I cannot reproduce this in VS Code.
  • I cannot reproduce this in GitHub Codespaces.

Are you accessing code-server over HTTPS?

  • I am using HTTPS.

Notes

No response

Activity

  1. added
    bugSomething isn't working
    triageThis issue needs to be triaged by a maintainer
    on Apr 23, 2023
  2. 502647092 commented on Apr 23, 2023

    @502647092
    Author

    I fix it by modify nginx config
    Origin Config

                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-Host    $host:$server_port;
                proxy_set_header      X-Forwarded-Proto   $scheme;

    Modified

                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-Host    $host;    <=== remove port
                proxy_set_header      X-Forwarded-Proto   $scheme;
  3. changed the title [-][Bug]: proxy by nginx origin check error[/-] [+][Bug]: proxy by nginx websocket origin check error[/+] on Apr 23, 2023
  4. code-asher commented on Apr 24, 2023

    @code-asher
    Member

    Oh interesting! We should make special exceptions for 443 and 80. #6166

  5. mashroomxl commented on Nov 12, 2023

    @mashroomxl

    try nginx config as follows:

    location ~ ${your frontend url pattern} {
        # add it if your url is dynamic
        resolver {your DNS server}
        
        # trick here, consult here for Nginx official doc
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        # trick here, if absent, the server will block the websocket request if the origin is NOT equal to the host
        proxy_set_header Origin http://${your backend host}/;
        proxy_set_header X-Forwarded-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 Accept-Encoding gzip;
        proxy_cookie_domain ${your backend host} ${your frontend host};
        
        proxy_pass ${your backend url pattern};
    }

    config above working for me. my scene:

    • code-server: 4.18.0, running in an container of Kubernetes
    • nginx:1.9.7, running in an container of another Kubernetes.
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

    bugSomething isn't workingtriageThis issue needs to be triaged by a maintainer

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions