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

How to Proxy Multiple Code-Servers via Nginx? #7036

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

I have multiple code-servers deployed in Docker containers. They are located at 127.0.0.1:13001, 127.0.0.1:13002, and so on. How can I achieve this through Nginx? For example, accessing /code/13001 should forward to 127.0.0.1:13001, and accessing /code/13002 should forward to 127.0.0.1:13002. It's important to note that the ports I mentioned (e.g., 13001) are not fixed.

I tried using the following configuration, but the browser cannot open the page normally.
企业微信截图_17288923142006
1728892397496
1728892417464
1728892443648

You must be logged in to vote

Make sure to include all the other headers as well. NGINX will not forward web sockets without Upgrade and Connection. I would include Host and Accept-Encoding as well.

Replies: 2 comments 5 replies

Comment options

I think once you use a regex you have to tell NGINX what the full target is, but I am not sure. This seems to work for me:

proxy_pass http://127.0.0.1:1ドル2ドル$is_args$args;
You must be logged in to vote
5 replies
Comment options

Thank you very much for being willing to help me!! But I still haven't solved it。

I have modified nginx according to your suggestion and hope to use/vscode/31013/proxy to access it http://127.0.0.1:31013
企业微信截图_17291354477082

After the nginx - s reload, I accessed it using a browser http://192.168.8.74:31013/ , can be accessed normally
企业微信截图_17291354702664

But I use https://vscode.rd.supcon.com/vscode/31013/ The page displays' not found '
企业微信截图_17291354936262

To verify if there is an issue with nginx, I will follow your answers in other posts. Added a section of ngixn configuration:
企业微信截图_17291355435666

After nginx - s reload, access it again through the browser: https://vscode.rd.supcon.com/code/ , can be accessed normally
企业微信截图_17291355703776

Comment options

Your location is a little different than what you originally posted. This is what I was using (notice the 2ドル):

location ~/code/(\d+)(/.*)?$ {
 proxy_pass http://127.0.0.1:1ドル2ドル$is_args$args;
 proxy_set_header ... etc etc ....

But, I was able to make ~ ^/vscode/(.*)/?$ work by omitting the slash in proxy_pass:

location ~ ^/vscode/(.*)/?$ { 
 proxy_pass http://127.0.0.1:1ドル$is_args$args; 
 proxy_set_header ... etc etc ....
Comment options

I used your configuration:
企业微信截图_17364973836710

When I opened the following URL in my browser: https://hos-studio.rd.supcon.com/vscode/15555/

I noticed that the page resources loaded correctly, but its WebSocket was not properly forwarded.
企业微信截图_17364976371527

Comment options

Make sure to include all the other headers as well. NGINX will not forward web sockets without Upgrade and Connection. I would include Host and Accept-Encoding as well.

Answer selected by yuzhuoheng
Comment options

@yuzhuoheng 这个问题你解决了吗

You must be logged in to vote
0 replies
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 によって変換されたページ (->オリジナル) /