tugberk
tugberk

Reputation: 58484

Request hangs for nginx reverse proxy to an ASP.NET 5 web application on docker

I am trying to get nginx, ASP.NET 5, Docker and Docker Compose working together on my development environment but I cannot see it working so far. This is the state where I am now and let me briefly explain here as well.

I have the following docker-compose.yml file:

webapp:
  build: .
  dockerfile: docker-webapp.dockerfile
  container_name: hasample_webapp
  ports:
    - "5090:5090"

nginx:
  build: .
  dockerfile: docker-nginx.dockerfile
  container_name: hasample_nginx
  ports:
    - "5000:80"
  links:
    - webapp:webapp

docker-nginx.dockerfile file:

FROM nginx
COPY ./nginx.conf /etc/nginx/nginx.conf

and docker-webapp.dockerfile file:

FROM microsoft/aspnet:1.0.0-rc1-update1

COPY ./WebApp/project.json /app/WebApp/
COPY ./NuGet.Config /app/
COPY ./global.json /app/
WORKDIR /app/WebApp
RUN ["dnu", "restore"]
ADD ./WebApp /app/WebApp/

EXPOSE 5090
ENTRYPOINT ["dnx", "run"]

nginx.conf file:

worker_processes 4;

events { worker_connections 1024; }

http {
    upstream web-app {
        server webapp:5090;
    }

    server {
      listen 80;

      location / {
        proxy_pass http://web-app;
        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;
      }
    }
}

All good and when I run docker-compose up, it gets two containers up and running which is also nice. From the host, when I hit localhost:5000, the request just hangs and when I terminate the request, nginx writes out a log through docker compose indicating 499 HTTP response.

Any idea what I might be missing here?

Update:

I added some logging to ASP.NET 5 app and when I hit localhost:5000, I can verify that request is being send to ASP.NET 5 but it's being terminated immediately giving a healthy response judging from the 200 response. Then, nginx sits on it util I terminate the request through the client.

enter image description here

Upvotes: 4

Views: 1777

Answers (1)

Kévin Chalet
Kévin Chalet

Reputation: 42080

This is a known bug in Kestrel RC1: https://github.com/aspnet/KestrelHttpServer/issues/341

You can work around it by forcing Connection: keep-alive:

proxy_set_header Connection keep-alive;

Upvotes: 2

Related Questions