<p>I've recently being learning about Kubernetes and I have deployed a service which contains a .NET Core 7 REST API into a pod. This pod/service is configured with it's ClusterIP and with NGINX port as well.</p>
<p>Whenever I would want to access the static files which is stored under this path in this screenshot:
<a href="https://i.stack.imgur.com/DZwZz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DZwZz.png" alt="first folder which is &quot;app&quot;" /></a>
<a href="https://i.stack.imgur.com/JTD9q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JTD9q.png" alt="wwwroot folder where the static files are" /></a></p>
<p>The path will be &quot;app&gt;wwwroot&gt;icons&gt;svg&gt;anyimagesname.svg&quot;.</p>
<p>My localhost address for 127.0.0.1 has been configured to have a DNS of <a href="http://www.chorebear.com" rel="nofollow noreferrer">www.chorebear.com</a> hence the complete URL to access the static file will be <a href="http://chorebear.com/icons/svg/afghanistan_adobe_express.xml" rel="nofollow noreferrer">http://chorebear.com/icons/svg/afghanistan_adobe_express.xml</a></p>
<p>But everytime I hit this URL, it says &quot;NGINX 404 Not Found&quot;. Is there any issue with the service itself? Any help would help in this. Thanks!.</p>
<p><a href="https://i.stack.imgur.com/Mh5De.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mh5De.png" alt="Not found 404 Error" /></a></p>
<pre><code>var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
var sqlConnectionBuilder = new SqlConnectionStringBuilder();
if (builder.Environment.IsDevelopment())
{
    sqlConnectionBuilder.ConnectionString = builder.Configuration.GetConnectionString(&quot;Chorebear_Connection&quot;);
    sqlConnectionBuilder.UserID = builder.Configuration[&quot;UserId&quot;];
    sqlConnectionBuilder.Password = builder.Configuration[&quot;Password&quot;];
} else if (builder.Environment.IsProduction()) 
{
    sqlConnectionBuilder.ConnectionString = builder.Configuration.GetConnectionString(&quot;Chorebear_Connection&quot;);
    // sqlConnectionBuilder.UserID = builder.Configuration[&quot;UserId&quot;];
    // sqlConnectionBuilder.Password = builder.Configuration[&quot;Password&quot;];
}

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext&lt;ChoreBearContext&gt;(options =&gt; options.UseSqlServer(sqlConnectionBuilder.ConnectionString));

//Registering services and classes which are dependency injection
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddIdentity&lt;User, UserRole&gt;().AddDefaultTokenProviders();
builder.Services.Configure&lt;IdentityOptions&gt;(options =&gt; 
{
    options.User.RequireUniqueEmail = true;
    options.Password.RequiredLength = 8;
    
    options.SignIn.RequireConfirmedEmail = true;
});
builder.Services.AddScoped&lt;IUserStore&lt;User&gt;, UserStore&gt;();
builder.Services.AddTransient&lt;IRoleStore&lt;UserRole&gt;, RoleStore&gt;();
builder.Services.AddScoped&lt;ICategoryOfTaskRepo, CategoryOfTaskRepo&gt;();
builder.Services.AddScoped&lt;ITaskRepo, TaskRepo&gt;();
builder.Services.AddScoped&lt;IAccountRepo, AccountRepo&gt;();

//Registering utility classes which are dependency injection
builder.Services.AddScoped&lt;IEmailUtility, EmailUtility&gt;();
builder.Services.AddScoped&lt;IPasswordHasher&lt;User&gt;, PasswordHasher&lt;User&gt;&gt;();

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.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.UseStaticFiles();

PrepDb.PrepPopulation(app, builder.Environment.IsProduction());

app.Run();
</code></pre>

Adrian Joseph
<p>Middleware order is very important, your <code>app.UseStaticFiles</code> is too late move it closer to the start of the pipeline:</p>
<pre><code>// ...
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseAuthorization();

app.MapControllers();
</code></pre>
<p>Read more:</p>
<ul>
<li><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/middleware/?view=aspnetcore-7.0" rel="nofollow noreferrer">ASP.NET Core Middleware</a></li>
<li><a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-7.0" rel="nofollow noreferrer">Static files in ASP.NET Core</a></li>
</ul>
