<p>EDIT: I rewrote the question with a fully reproducible example.</p>
<p>I have a sample Django app with the base getting started <a href="https://docs.djangoproject.com/en/3.2/intro/tutorial01/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/3.2/intro/tutorial01/</a>, that is, there are two paths <code>/admin</code> and <code>/polls</code>.</p>
<p>If I deploy the app using NodePort, I can access both paths without issues. However, I haven't managed to do the same with Nginx ingress controller. I have tried several combinations of annotations and paths to no avail.</p>
<p>So, assume this yaml:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: django
  name: django
spec:
  selector:
    matchLabels:
      app: django
  template:
    metadata:
      labels:
        app: django
    spec:
      containers:
      - image: &quot;ay0o/django-ingress:latest&quot;
        name: django
# ---
# apiVersion: v1
# kind: Service
# metadata:
#   name: django
# spec:
#   ports:
#   - nodePort: 31000
#     port: 8000
#     targetPort: 8000
#   selector:
#     app: django
#   type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: django
spec:
  ports:
  - port: 8000
  selector:
    app: django
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: django
spec:
  rules:
  - http:
      paths:
      - path: /django
        pathType: Prefix
        backend:
          service:
            name: django
            port:
              number: 8000

</code></pre>
<p>when I use NodePort, <code>http://localhost:31000/admin</code> and <code>http://localhost:31000/polls</code> work fine.</p>
<p>when I use Ingress, <code>http://localhost/django</code> returns a 404 from django (because the path is neither admin nor polls), but <code>http://localhost/django/admin</code> and <code>http://localhost/django/polls</code> return a 404 from nginx, meaning the ingress is not properly routing.</p>
<p>so, what should I change so that <code>http://localhost/django/admin</code> and <code>http://localhost/django/polls</code> will not return 404?</p>

<p>I have come to the conclusion that it's not possible to use path-based Ingress for a Django app, probably due to something related to Django's internals.</p>
<p>Every example out there uses host-based rules, and indeed, that just work. For example, the Ingress above can be changed to the following, and it will work.</p>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: django
spec:
  rules:
  - host: localhost
    http:
      paths:
      - pathType: Prefix
        path: &quot;/&quot;
        backend:
          service:
            name: django
            port:
              number: 8000
</code></pre>
<p>If anyone come up with a solution using path-based routing, feel free to answer the question.</p>
