-
Notifications
You must be signed in to change notification settings - Fork 5.9k
[Bug]: Port forwarding with suburl makes the forwarded links corrupted . #5792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm having the same browser output when I try using jupyter-lab as well. I'm using code-server in a docker container behind a reverse proxy (caddy). I noticed when I prepend the path of the 404 requests with the path '/proxy/8888/' it fetches the desired resource successfully. In my case it looks like because code-server's proxy strips the '/proxy//' portion of the path it fails. |
Hmm 🤔 Can this be fixed via the environment variable? Here are the notes from the release about this feature:
I don't work with Jupyter notebooks or jupyter-lab so I'm not sure what to expect here. If you can provide some tests cases and what the expected URLs would be, I can help more. |
Woah that's weird. Okay let me summarize to make sure I'm understanding. You're running code-server on You pass When you access said process i.e. Jupyter running at
Agreed! So let's try this:
If that works, then try running Jupyter on 8888 and try again. At least that's what I'd do. I don't know if Jupyter needs to have some environment variable or something to run behind a subpath but we can check that next. I just want to make sure the port forwarding works with your setup first. |
@jsjoeio And , I found this https://jupyter-notebook.readthedocs.io/en/stable/public_server.html#running-the-notebook-with-a-customized-url-prefix, and I followed it. And Logs
And for UPD: The reverse proxy server used by code-server makes jupyter thinks that you are accessing path |
Does this need to include the full url? i.e
Nice work!!!
Argh :( that is very confusing indeed. When @code-asher is back, maybe he'll have some ideas about this and know if there's anything we can do to make it better from the code-server side. Sorry for all the trouble! |
It doens't need to include the full url , there are descriptions in jupyter's docs
|
Yeah many applications use absolute URLs unfortunately and default to The sub-domain proxy method is superior since it does not have the same issue but it needs to be enabled via the
(Alternatively the proxy could be implemented via a separate reverse proxy.) |
I wonder if there is a way we can surface help around this, maybe via a tooltip or text underneath the forwarded port? Or something like a "help me" button that triggers a notification or opens documentation? |
I like that! We could add a doc and then in the message that pops up about the forwarded port, add a link below and link to the docs. |
Oh , thank you for explaining.
I wonder whether it's possible to add a field which lets us input 2 URLs A and B , the the reverse proxy will replace all 'A' in the resource location links from the page with 'B' .
For example , if we input 'https://code.example/' as the URL to be replaced(A) and 'https://code.example/proxy/8888/' as the URL to replace with (B) . Then when the proxy is about to send the requested page(or js or something else) it will look for 'https://code.example/' and replace it with 'https://code.example/proxy/8888' if it is a link . (Also maybe adding a check box to disable the link check?)
A bit like 'sub_filter' parameter in nginx.
But does it work for dynamic sites and is the implementation complicated?
Or , is it possible to change how code server handles 404? Like when it handles 404 it checks the referer string in the http header and check whether it's linked there from a proxied page , if so , it will redirect it to the correct URL .(But maybe this method is complicated and buggy?)
|
Hmm...that sounds a bit out of scope for now. We want to keep it as close to upstream (VS Code) as possible. Let me know if there's another way we can help you though. |
Yeah I think for advanced proxy configuration it might be better to set up NGINX or Caddy instead of using code-server's built-in. Also if all you are looking for is to avoid stripping the base path then we have another proxy endpoint |
I...tried Note:This configuration doesn't fully work , use the one below Configuration
The subs_filter regex comes from https://regex101.com/r/zY1lJ7/1 And with the But from there you can see there's still |
@code-asher @jsjoeio Here is the nginx configuration. Configuration
When accessing What I have tested :
|
Ahhh wow, nice debugging and thanks for posting your solution! I guess for now this is where we point people if they run into this. |
@a279437145, It is a nice solution. But what if I have already set the code-server through the Nginx server? e.g. |
As you are already using nginx and serving code-server behind subpath , I think you can merge the configuration files .
I think..just make your 'location /code-server' block at top so the other configurations wont affect it .So I think merging them won't cause conflicts.
I have tons of homework to do now and I can't test , I'll test it this weekend and reply here.
Sorry for keep you waiting ~
|
@qianchd Just tested. Configuration
Remember to change the It works normally . And the reverse proxy still works , no conflicts. Actually , since nginx is already forwarding ports at
|
I am having the same issue I am running a code-server on docker(image: lscr.io/linuxserver/code-server). I am building a react application with vite dev server on the code-server. when i if I try to use ngnix but it ask for authorization. as shown in the attach. How can i solve this problems? need your help |
Have you looked through Discussions? We've helped people with Vite in the past. Maybe this has your answer: #4541 |
I have looked https://github.com/coder/code-server/discussions/4541 but does not solve the stripping of expectation Reality My second question is how to remove the authorization access on the code-server. because i edit the
the code-server is running on |
401 is from code-server , not from nginx or vite . |
Sounds like you need to set a base path or base URL for your application. That's where I'd look at least. You'll need to pass |
@jsjoeio thanks for the reply. I did set the base as For the authorization, i try your suggestion. |
Yes i know the 401 is from code-server not the nginx. Thats why i was thinking of removing or disabling the authorization access in code-server. |
But to use nginx you don't have to disable code-server authorization.
|
@kamskanagi
Is your problem solved?
And maybe later I'll write a tutorial here about how to use this . ^_^
|
I'm not an experienced nginx user , so this isn't a perfect solution . 1.Install nginxIt's the same as normal nginx installation , and nginx from the package manager should work , simply install with : (on Debian/Ubuntu) sudo apt install nginx Or you can install with any way you like. 2.ConfigureCreate a You can also download it via ConfigurationThe same as https://gist.github.com/a279437145/d8c1565e49e5eda7577e68ec519660bc
Then replace the double braces surrounded contents with yours. (Remember to use a different port than code-server)
3.UsageAccess https://{IP}:{NGINX_PORT}/proxy/{SERVICE_PORT}
Notice1.This uses 2.This solution uses cookie , so don't use private mode in browser or disable cookie. 3.The default |
I am curious about the ip address. The address "https://{IP}:{NGINX_PORT}/proxy/{SERVICE_PORT}" only can be visited in container? |
@jxfruit
No , it can be visited from anywhere that can access the machine running nginx.
So you should be able to access it outside the container (with an address like {CONTAINER_IP}:{NGINX_PORT})
By the way , if you mean accessing it from a faraway host , you should forward the nginx port.(Just like forwarding the code-server port)
Then if you still can only access it inside the container , you may check the configuration file.
Especially check if nginx is exposed to the host machine.(I think it always is,maybe)
|
@code-asher Is there a way for code-server's built-in port-forwarding to forward the full url path to backend server? |
Yup, use It would be nice if in the port forwarding panel we had an option to choose which one you want, since right now the only way to even know about |
One caveat though, code-server does not know about its own prefix, so this will result in |
Oh, that's a bit unexpected... |
@code-asher In addition, what I want to claim is that even though code-server itself doesn't need such a param like |
Yup, exactly this. Are you able to host at a subdomain instead? Something like
100% agree. I think it would be reasonable to add a |
I opened an issue: #6770 Not sure I can get to it any time soon, but happy to take pull requests. |
@code-asher I see. Thank you for your clear explanation and understanding and support! |
Is there an existing issue for this?
Similar [Bug]: absproxy strips /absproxy/<port> from request path #5439 ;
OS/Web Information
code-server --version
: 4.8.3 977b853 with Code 1.72.1Steps to Reproduce
jupyter notebook
in terminal , and forward the port (should be forwarded automatically)Expected
Jupyter notebook shows up a correct UI and works without problems.
Actual
The jupyter notebook showed up with a unformatted UI (because css and js files are requested with a corrupted URL, only the
https://192.168.0.114:28080/proxy/8888/login?next=%2Ftree
is requested correctly)if logging in to the notebook it redirected me to
https://192.168.0.114:28080/?next=/tree
, which is obviously wrong (code-server is serving there)eg , for the
logo.png
, it requested forhttps://192.168.0.114:28080/static/base/images/logo.png?v=<a long string>
, but it should request forhttps://192.168.0.114:28080/proxy/8888/static/base/images/logo.png?v=<a long string>
Logs
Logs
Screenshot/Video
Behavior
Run jupyter:



Forward port:
Access it:
Browser console output
Explaination
The correct URL:


The corrupted URL:
Does this issue happen in VS Code or GitHub Codespaces?
Are you accessing code-server over HTTPS?
Notes
Code-server is running on a
lxc
container , it exposed the port 8888 to the server host , and I used iptables(iptables -t nat -A PREROUTING -p tcp --dport 28080 -j DNAT --to-destination 10.154.46.4:8080
, where 28080 is the server exposed port , and 10.154.46.4:8080 is the container exposed port).It is using a self-signed certificate with
cert
andcert-key
params in the config file (not serving through nginx/caddy)Also , this bug makes the pdf viewer from LaTeX workshop not working properly.
Is it because of relative path ? But
jupyter
and LaTeX workshop aren't my project , i don't know where I can make changes.Subdomains may work , but I don't have a domain for my server.
The text was updated successfully, but these errors were encountered: