-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Can I make code server access on a sub path? #6987
-
I run code server on a docker container which I access from various machines using http://machine-name.local:8080.
Is it possible to serve the site on http://machine-name.local/code? When I try to proxy it using NGINX it doesn't work.
Beta Was this translation helpful? Give feedback.
All reactions
I tried it out and got the same error. It looks like NGINX is sending requests with double slashes like //login for some reason. I was able to get it working like this:
location = /code {
return 302 /code/$is_args$args;
}
location /code/ {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
Replies: 2 comments 6 replies
-
Sure, that should work. Something like this, I think:
server {
listen 80;
listen [::]:80;
server_name machine-name.local;
location /code {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
}
Note that the trailing slash in proxy_pass is important, it tells NGINX to rewrite the path which code-server requires.
Beta Was this translation helpful? Give feedback.
All reactions
-
I have the following setup following your example but when I type in http://diskstation/code, it redirects to http://diskstation/?folder=/workspace/docker/projects. When I do http://diskstation.local/code, it redirects to http://diskstation.local/login. In both redirects the page lands on a 404 page.
server {
listen 80;
listen [::]:80;
server_name diskstation.local diskstation.sugar-thorn.ts.net diskstation;
# Common proxy settings
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_redirect off;
location /code {
proxy_pass http://localhost:8443/;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
location /other-app {
proxy_pass http://localhost:8988;
}
...
Any ideas what I'm doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions
-
I get 401 not found when I try diskstatation.local/code/
Beta Was this translation helpful? Give feedback.
All reactions
-
Are you sure it is 401 not found? That is an unusual combination of code and status.
Can you verify whether the error is coming from code-server or NGINX?
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry I'm mistaken, its a 404 header. The page is black and theres some white text which says says "Not found" when I hit https://diskstation/code/
When I hit https://diskstation/code without the trailing slash, I see the URL is redirected to http://diskstation/?folder=/workspace/docker/projects it it shows a 404 Not Found page, but it looks like a generic nginx 404 page unlike the first URL.
Beta Was this translation helpful? Give feedback.
All reactions
-
I tried it out and got the same error. It looks like NGINX is sending requests with double slashes like //login for some reason. I was able to get it working like this:
location = /code {
return 302 /code/$is_args$args;
}
location /code/ {
proxy_pass http://localhost:8080/;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header Accept-Encoding gzip;
}
Beta Was this translation helpful? Give feedback.
All reactions
-
This has got it working! Thank you!
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1