- 
  Notifications
 You must be signed in to change notification settings 
- Fork 6.3k
How to Proxy Multiple Code-Servers via Nginx? #7036
-
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 
Beta Was this translation helpful? Give feedback.
All reactions
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
-
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;
Beta Was this translation helpful? Give feedback.
All reactions
-
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 
Beta Was this translation helpful? Give feedback.
All reactions
-
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 ....
Beta Was this translation helpful? Give feedback.
All reactions
-
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 
Beta Was this translation helpful? Give feedback.
All reactions
-
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.
Beta Was this translation helpful? Give feedback.
All reactions
-
@yuzhuoheng 这个问题你解决了吗
Beta Was this translation helpful? Give feedback.