Asp.net 如何在kubernetes中部署.net和nginx?

Asp.net 如何在kubernetes中部署.net和nginx?,asp.net,.net,docker,nginx,Asp.net,.net,Docker,Nginx,我已经在docker中部署了.net+nginx。 当我想去的时候,我看到了 但不是 我怎样才能解决这个问题 docker-compose.yaml version: '3' services: app: build: ./app ports: - "80:80" nginx: build: ./nginx ports: - "8080:8080" links: - app .net Dockerfile F

我已经在docker中部署了.net+nginx。 当我想去的时候,我看到了 但不是

我怎样才能解决这个问题

docker-compose.yaml

version: '3'
services:
  app:
    build: ./app
    ports:
      - "80:80"

  nginx:
    build: ./nginx
    ports:
      - "8080:8080"
    links:
      - app
.net Dockerfile

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS final
WORKDIR /app
COPY . .
EXPOSE 5000
ENTRYPOINT ["dotnet", "WebApplication4.dll"]
nginx

nginx.conf

worker_processes 4;

events { worker_connections 1024; }

http {
  # Nginx will handle gzip compression of responses from the app server
  gzip on;
  gzip_proxied any;
  gzip_types text/plain application/json;
  gzip_min_length 1000;

  server {
    listen 80;

    # Nginx will reject anything not matching /api
    location /api {
      # Reject requests with unsupported HTTP method
      if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE)$) {
        return 405;
      }

      # Only requests matching the whitelist expectations will
      # get sent to the application server
      proxy_pass http://172.28.0.3:5000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_cache_bypass $http_upgrade;
    }
  }
}

谢谢大家。我解决了我的问题。在docker compose中,需要添加网络模式:“主机”

nginx:


网络模式:“主机”

看起来您的
nginx.conf
将只代理与/api匹配的请求。您是在访问/api地址还是试图访问/root?
worker_processes 4;

events { worker_connections 1024; }

http {
  # Nginx will handle gzip compression of responses from the app server
  gzip on;
  gzip_proxied any;
  gzip_types text/plain application/json;
  gzip_min_length 1000;

  server {
    listen 80;

    # Nginx will reject anything not matching /api
    location /api {
      # Reject requests with unsupported HTTP method
      if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE)$) {
        return 405;
      }

      # Only requests matching the whitelist expectations will
      # get sent to the application server
      proxy_pass http://172.28.0.3:5000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_cache_bypass $http_upgrade;
    }
  }
}