NGINX 容器不使用 Traefik / Kubernetes 加载静态文件

NGINX Container Not Loading Static Files using Traefik / Kubernetes

我是 运行 Kubernetes (AKS) 上的 Traefik Ingress 控制器。我已经使用 Traefik Ingress 成功部署了我的 Django 应用程序,但它当前没有加载任何静态文件(因此样式不起作用)。

静态文件由带有 /static 的自定义 NGINX 容器提供。因此,如果我的域名是 xyz.com,则从 xyz.com/static.

提供静态服务
apiVersion: v1
kind: Service
metadata:
  name: nginxstaticservice
  labels:
    app: nginxstatic
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
    - name: http
      port: 80
      targetPort: 80
      protocol: TCP
  selector:
    app: nginxstatic

---

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: nginxstatic-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.frontend.rule.type: PathPrefixStrip
    # traefik.ingress.kubernetes.io/frontend-entry-points: http,https
spec:
  rules:
  - host: xyz.com
    http:
      paths:
      - path: /static
        backend:
          serviceName: nginxstaticservice
          servicePort: http

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginxstatic-deployment
  labels:
    app: nginxstatic
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxstatic
  template:
    metadata:
      labels:
        app: nginxstatic
    spec:
      containers:
      - name: nginxstatic
        image: nginxstatic:latest
        ports:
        - containerPort: 80
      imagePullSecrets:

这是 NGINX 容器上的 default.conf 运行(之前在网站配置中工作。

server {
   listen                      80;
   server_name                 _;
   client_max_body_size        200M;
   set                         $cache_uri $request_uri;

   location                    = /favicon.ico { log_not_found off; access_log off; }
   location                    = /robots.txt  { log_not_found off; access_log off; }
   ignore_invalid_headers      on;
   add_header                  Access-Control-Allow_Origin *;

   location /static {
       autoindex on;
       alias /static;
   }

   location /media {
       autoindex on;
       alias /media;
   }

   access_log                  /var/log/nginx/access.log;
   error_log                   /var/log/nginx/error.log;
}

已在评论中解决,错误使用 PathPrefixStrip 导致 Nginx 看到与预期不同的路径。