[英]Cannot Reach Kestrel + NGINX (proxy) Website Hosted in LXD Container
I tried hosting my ASPNet Core web inside a LXD container together with NGINX as reverse proxy server, but to no avail.我尝试将我的 ASPNet Core web 与 NGINX 作为反向代理服务器一起托管在 LXD 容器中,但无济于事。
When I have Kestrel running through dotnet <app.dll>
command, the browser (Firefox) returns Unable to Connect
.当我通过
dotnet <app.dll>
命令运行 Kestrel 时,浏览器 (Firefox) 返回Unable to Connect
。 However, when I don't have the app running, which in this case, just NGINX service, the browser returns standard NGINX 502 Bad Gateway.但是,当我没有运行应用程序时,在这种情况下,只是 NGINX 服务,浏览器返回标准 NGINX 502 Bad Gateway。
I am starting to think, the problem might lie on Kestrel.我开始想,问题可能出在红隼身上。 But, as far as I understand, whenever we use reverse-proxy, Kestrel doesn't need to be configured for outside access.
但是,据我了解,每当我们使用反向代理时,都不需要为外部访问配置 Kestrel。
However, I managed to access the website when I hosted it in a Linux VM (not container).但是,当我将网站托管在 Linux 虚拟机(不是容器)中时,我设法访问了该网站。 I used the same configuration too.
我也使用了相同的配置。 Is there any missing configuration to enable this feature on LXD containers?
在 LXD 容器上启用此功能是否缺少任何配置?
Below is my NGINX server configuration:下面是我的 NGINX 服务器配置:
server {
listen 80;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
I wonder if the broken part is on NGINX, Kestrel or LXD.我想知道损坏的部分是否在 NGINX、Kestrel 或 LXD 上。 What should I do?
我应该怎么办? I can ping the container from outside just fine.
我可以从外面 ping 容器就好了。 Also, the website hosted in the container is inaccessible to other containers too.
此外,容器中托管的网站也无法访问其他容器。
Somehow, you need to supply the allowed urls to Kestrel even though it is using NGINX as a reverse proxy.不知何故,您需要向 Kestrel 提供允许的 url,即使它使用 NGINX 作为反向代理。 This ONLY happens in LXD container;
这只发生在 LXD 容器中; meaning the Kestrel and NGINX are hosted in a LXD container.
这意味着 Kestrel 和 NGINX 托管在 LXD 容器中。
Here is the solution.这是解决方案。 I added the environment variable in the command line and voila, it works.
我在命令行中添加了环境变量,瞧,它可以工作了。
ASPNETCORE_URLS=http://0.0.0.0:80 dotnet <your_app.dll>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.