linuxasp.net-corekestrel-http-serverlxd

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.

When I have Kestrel running through dotnet <app.dll> command, the browser (Firefox) returns 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.

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.

However, I managed to access the website when I hosted it in a Linux VM (not container). I used the same configuration too. Is there any missing configuration to enable this feature on LXD containers?

Below is my NGINX server configuration:

    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. What should I do? I can ping the container from outside just fine. Also, the website hosted in the container is inaccessible to other containers too.


Solution

  • Somehow, you need to supply the allowed urls to Kestrel even though it is using NGINX as a reverse proxy. This ONLY happens in LXD container; meaning the Kestrel and NGINX are hosted in a LXD container.

    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>