繁体   English   中英

nginx 中的动态 proxy_pass 与 gitpod 等端口

[英]Dynamic proxy_pass in nginx with ports like gitpod

如何像gitpod.com一样在 nginx 中设置动态 proxy_pass :

我已经有通配符证书

例如,在 Gitpod 中你有一个VM ,如果你启动一个像8081这样的端口,你的 URL 是: https://8081-some-uuid.ws-us02.gitpod.io/

按照这个想法顺序,我想配置类似的东西

8082.example.com -> http://localhost:8082
8081.example.com -> http://localhost:8081
8080.example.com -> http://localhost:8080

启用站点/example-com.config

server {
    server_name *.example.com;
    listen 80;

    location / {
        // how config this??
        proxy_pass http://localhost:(¿dynamic port?);

        proxy_set_header Connection 'upgrade';
        proxy_set_header Upgrade $http_upgrade;
        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 $http_x_forwarded_proto;
    }
}

您可以使用正则表达式来捕获请求的子域部分,而不是使用带有server_name的通配符名称。 有关详细信息,请参阅此文档

例如:

server_name "~^(?<subdomain>[0-9]{4})\.example\.com$";
proxy_pass http://localhost:$subdomain;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM