Swagger UI "Try It Out" option for DotNet Core 6 API app does not work with nginx ingress in azure kubernetes service (aks) , the path for service does not get added in the URL . I have tried multiple options like adding swagger endpoint in program.cs or removing the target-rewrite option but nothing worked.

The swagger UI works fine with localhost and with LoadBalancer service but not with nginx controller as shown below:

Below is my Ingress configuration

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: hello-world-ingress
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "false"
    nginx.ingress.kubernetes.io/use-regex: "true"
    nginx.ingress.kubernetes.io/rewrite-target: /$1
spec:
  ingressClassName: nginx
  rules:
  - http:
      paths:
      - path: /serv1/(.*)
        pathType: Prefix
        backend:
          service:
            name: myapp
            port:
              number: 80

Below is how my "program.cs" file looks

var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI();
//     options =>
//     options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
//     //options.RoutePrefix = "serv1/swagger";
// });
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
						

The LB nginx ingress provisions sets its heath check to look at the / path, and the dotnet api doesnt respond at all on /! You can change the path when you install the controller as described here, that should ping it to life: https://github.com/Azure/AKS-Construction/issues/573#issuecomment-1527253720