Error when configuring asp net with nginx

Viewed 35

I would like to start asp net core server with nginx But when redirecting, nginx takes me to the asp address and I get an error. Although it should make a redirect without transferring. What am I doing wrong

Here is my nginx config

server{
listen 8888;
location /{
    proxy_pass http://localhost:5010;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
}

Here's c#

using Microsoft.AspNetCore.HttpOverrides;
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production 
scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseForwardedHeaders(
new ForwardedHeadersOptions(){
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
}
);

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

 app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
0 Answers
Related