Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Can I make code server access on a sub path? #6987

Answered by code-asher
imran0 asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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.

You must be logged in to vote
0 replies
Comment options

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?

You must be logged in to vote
6 replies
Comment options

I get 401 not found when I try diskstatation.local/code/

Comment options

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?

Comment options

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.

Comment options

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;
}
Answer selected by imran0
Comment options

This has got it working! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /