Movatterモバイル変換


[0]ホーム

URL:


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

Question: Using code-server with nginx and base path appended#1739

Answeredbycode-asher
Lesmiscore asked this question inQ&A
Discussion options

I expose (old) code-server via nginx, with the base path set. (e.g. expose code-server at/vs-code/)
(SSL is configured at nginx, so I don't need SSL oncode-server.)
Is it possible to usecode-server with the base path in the current version? If it's possible, how should I configurecode-server?

You must be logged in to vote

Yup, the critical part is the trailing slash onproxy_pass.

    location /vs-code/ {      proxy_pass http://localhost:8080/;

That's what makes nginx rewrite the URL without the base path.

Replies: 6 comments 1 reply

Comment options

cc@code-asher

You must be logged in to vote
0 replies
Comment options

@nao20010128nao if code server doesn't have the ability to set base path, you can always setup nginx torewrite requests.

You must be logged in to vote
0 replies
Comment options

See the Deep Ocean tutorial I put in#1741

You must be logged in to vote
0 replies
Comment options

Yup, the critical part is the trailing slash onproxy_pass.

    location /vs-code/ {      proxy_pass http://localhost:8080/;

That's what makes nginx rewrite the URL without the base path.

You must be logged in to vote
0 replies
Answer selected bybpmct
Comment options

Makes sense, all our links are relative otherwise so that's why--base-path was removed.

You must be logged in to vote
0 replies
Comment options

We need a proxy_redirect to rewrite the 302 request returned by code-server to avoid routing to the wrong path.

Because code-server will return a 302 response withLocation: ./../login when openhttps://your.domain.com/code-server/

So the complete configuration should be like this:

location /code-server/ {            proxy_pass http://localhost:8080/;            proxy_set_header Host $host;            proxy_http_version 1.1;            proxy_set_header Upgrade $http_upgrade;            proxy_set_header Connection upgrade;            proxy_set_header Accept-Encoding gzip;            proxy_set_header X-Real-IP $remote_addr;            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;            # redirect rewrite            proxy_redirect ~^\./\.\./(.*)$ /code-server/$1;            proxy_redirect / /code-server/;}

Then openhttps://your.domain.com/code-server/ to access

You must be logged in to vote
1 reply
@code-asher
Comment options

Hmm strange, when you use a trailing slash inproxy_pass, NGINX is supposed to rewrite the base path out of the request, so code-server should just see/ and redirect to./login, which makeshttps://your.domain.com/code-server/ go tohttps://your.domain.com/code-server/login.

Maybe we have a bug in generating that relative path, although I am not sure what it could be. Or maybe NGINX is sending the wrong request path, but that seems less likely.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
6 participants
@Lesmiscore@dtsmith2001@nhooyr@nathanrpage97@github0null@code-asher
Converted from issue

This discussion was converted from issue #1739 on August 20, 2020 22:21.


[8]ページ先頭

©2009-2025 Movatter.jp