coder / code-server

VS Code in the browser
https://coder.com
MIT License
68.52k stars 5.61k forks source link

Blank page in proxy pass #1544

Closed 4nuragk closed 4 years ago

4nuragk commented 4 years ago

I have set up reverse proxy in apache for my local code-sever install.

Everything is okay till the login screen, but after that, I get nothing just blank screen. I checked the console log and its full of 200 errors.

Eg. I have set up code-server in local system with IP http://172.x.x.x:8000 and proxy-passed it to https://example.com/abc/test/code-server/

The command I used: Screenshot (17)

Where am I doing wrong?

tiborsekera commented 4 years ago

then, in your browser, if you go to http://172.18.0.3:8000, don't you get vscode?

4nuragk commented 4 years ago

then, in your browser, if you go to http://172.18.0.3:8000, don't you get vscode?

Yes, I get vs code when I visit the local ip. But proxy-pass isn't working. I even tried with --auth none flag. I just get a blank page.

Console log: Screenshot (18)

Proxy pass settings: Screenshot (19)

apache-conf setting(found it somewhere in the issues):

Screenshot (20)

I'm under huge pressure of getting this work done. Please help.

code-asher commented 4 years ago

Do you have the mod_proxy_wstunnel module enabled?

code-asher commented 4 years ago

Oh you've got a base path. You might just need to include it in the rewrite. Here's a configuration I just tested which seems to work:

<VirtualHost *:8080>
  ServerName localhost

  RewriteEngine On
  RewriteCond %{HTTP:Upgrade} =websocket [NC]
  RewriteRule /test/path/(.*) ws://localhost:8081/$1 [P,L]
  RewriteCond %{HTTP:Upgrade} !=websocket [NC]
  RewriteRule /test/path/(.*) http://localhost:8081/$1 [P,L]
</VirtualHost>
4nuragk commented 4 years ago

I tried that. Not working. I am getting the same error. After debugging I found something.

debug got message from vs code {"message":{"type":"options","id":"baQ06AJ0CeQaBICxDzAGSvf8","options":{"workbenchWebConfiguration":{"remoteAuthority":"172.16.112.2","logLevel":0},"remoteUserDataUri":{"$mid":1,"path":"/root/.local/share/code-server","scheme":"vscode-remote","authority":"172.16.112.2"},"productConfiguration":{"nameShort":"Code - OSS","nameLong":"Code - OSS","applicationName":"code-oss","dataFolderName":".vscode-oss","win32MutexName":"vscodeoss","licenseName":"MIT","licenseUrl":"https://github.com/Microsoft/vscode/blob/master/LICENSE.txt","win32DirName":"Microsoft Code OSS","win32NameVersion":"Microsoft Code OSS","win32RegValueName":"CodeOSS","win32AppId":"{{E34003BB-9E10-4501-8C11-BE3FAA83F23F}","win32x64AppId":"{{D77B7E06-80BA-4137-BCF4-654B95CCEBC5}","win32UserAppId":"{{C6065F05-9603-4FC4-8101-B9781A25D88E}","win32x64UserAppId":"{{C6065F05-9603-4FC4-8101-B9781A25D88E}","win32AppUserModelId":"Microsoft.CodeOSS","win32ShellNameShort":"C&ode - OSS","darwinBundleIdentifier":"com.visualstudio.code.oss","linuxIconName":"com.visualstudio.code.oss","licenseFileName":"LICENSE.txt","reportIssueUrl":"https://github.com/cdr/code-server/issues/new","urlProtocol":"code-oss","extensionAllowedProposedApi":["ms-vscode.references-view"],"commit":"28e91ba70cd70fa9adf3f2e3e3b87631b5667ecf","date":"2020-04-14T22:51:57.043Z","version":"1.43.2","extensionsGallery":{"serviceUrl":"https://extensions.coder.com/api","itemUrl":"","controlUrl":"","recommendationsUrl":""}},"nlsConfiguration":{"locale":"en","availableLanguages":{}},"commit":"28e91ba70cd70fa9adf3f2e3e3b87631b5667ecf"}}}

This is the debug log. Here, it is looking for directories(/root/.local/share/code-server) in 172.16.112.2. But that is not the server in which it is installed. That is the main server to which it is proxy-passed.

How do i make it look into the directory in which it is installed? I guess that might be the error. Also there is some websocket error in console log.

code-asher commented 4 years ago

The remote authority won't actually affect where it looks for the directory; all files and directories are only accessed on the local machine where code-server is running.

We always set the remote authority to the host header so that's just what your proxy is providing to code-server. I think the only thing it's used for is setting cookies but it won't be used if it's an IP address so in your case it shouldn't have any effect.

Were you able to confirm whether you have the mod_proxy_wstunnel module enabled? So far that's the only other way I've been able to replicate the issue.

fresh2dev commented 4 years ago

I also have this issue using a base-path behind a traefik proxy. It worked fine prior to v3.1. The web debugger is full of errors due code-server looking for dependencies at the root path; ignoring the base-path prefix.

code-asher commented 4 years ago

For Traefik this might help: https://github.com/cdr/code-server/issues/1608#issuecomment-627109454

joelcox22 commented 4 years ago

I had the same issue with nginx when just using the basic proxy_pass option alone. Works with:

location / {
      proxy_pass http://localhost:8000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
      proxy_set_header Host $host;
  }
4nuragk commented 4 years ago

I had the same issue with nginx when just using the basic proxy_pass option alone. Works with:

location / {
      proxy_pass http://localhost:8000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "Upgrade";
      proxy_set_header Host $host;
  }

Did you try doing that for a sub directory?

nhooyr commented 4 years ago

It's unlikely this is a bug with code-server.

Can you try to follow our setup guide with caddy and see if you can get it working?

See https://github.com/cdr/code-server/blob/master/doc/guide.md

If not I'll reopen.

martiiinthomas commented 3 years ago

I'm having this issue as well with code server using apache. I think this needs to be reopened.

nhooyr commented 3 years ago

@martiiinthomas It's very likely you don't have apache configured correctly. Please see our configuration guide.

https://github.com/cdr/code-server/blob/v3.7.4/doc/guide.md

We recommend caddy for easiest setup but there's also some docs on using nginx.

psuter80 commented 3 years ago

just found this issue because i was struggeling too but i got it to work. here is my apache proxy config:

Redirect "/ak22vf3/vscode" "/ak22vf3/vscode/"
<Location "/ak22vf3/vscode/">
    ProxyPass http://172.17.0.3:8080/
    ProxyPassReverse http://172.17.0.3:8080/
    ProxyPassReverse /
    RewriteEngine on 
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteCond %{HTTP:Connection} upgrade [NC]
    RewriteRule ^/?(.*) "ws://172.17.0.3:8080/" [P,L]
</Location>

this config needs mod_proxy, mod_proxy_wstunnel, mod_proxy_http and mod_rewrite to be enabled.

what i did to figure this out: i went to the before mentioned guide.md and basically went through the nginx documentation to decyper what that config does which made me realize, that I was missing the websocket proxy :)

@nhooyr i would suggest to add the above example to the setup guide. I was bound to apache because i needed some of its html rewrite functionalities for another container i was proxying :)

nhooyr commented 3 years ago

Thanks @psuter80

I opened https://github.com/cdr/code-server/issues/2452