简体   繁体   English

无法访问 Kestrel + NGINX(代理)网站托管在 LXD 容器中

[英]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.

相关问题 在 LXD 容器中运行 Xvfb - Running Xvfb in LXD container LXD public ip 到容器使用路由 - LXD public ip to container using routed 多个 web 应用程序容器是否可以托管在单个 NGINX 容器中? - Is it possible a multiple web application containers be hosted in a single NGINX container? 即使连接到端口,也无法到达 docker 容器 - cannot reach docker container even its connected to a port 无法从 docker 容器内部访问主机上的 quarkus 应用程序 - Cannot reach quarkus application on host from inside docker container NGINX docker 容器无法在 web 浏览器中访问 - NGINX docker container cannot be accessed in the web browser 是否建议在没有反向代理的情况下在 Linux 上运行 Kestrel? - Is running Kestrel on Linux without a reverse proxy recommended? 停止在kestrel上运行的运行dotnet核心网站 - Stop a running dotnet core website running on kestrel 如果托管在同一服务器上的网站无法加载,我如何重新启动 linux 服务器中的 NGINX 守护进程? - How do i restart NGINX daemon Process in linux server if a website hosted on the same server fails to load? 是否可以配置从Nginx到kestrel aspnet核心的kerberos转发 - Is it possible to configure the forwarding of a kerberos from Nginx to kestrel aspnet core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM