我正在尝试在 EC2 服务器上运行多个 Nodejs 应用程序。
rewrite ^(/\d+)$ $1/ redirect;
rewrite ^/(?<port>\d+)(.+)$ $2;
location / {
proxy_pass http://127.0.0.1:$port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
假设我在 1234 端口上运行应用程序。当我请求 127.0.0.1:1234 时。它没有通过。 我正在努力让它变得动态。它应该在任何端口上传递请求。
我尝试过硬编码端口。它工作正常。
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:3000;
}
}
有什么办法可以动态监听任何端口。
谢谢