
Код: Выделить всё
//ex.
// root
www.example.com/custom/path
// Desired
www.example.com/custom/path/Home/Privacy
// Actual - 404 error as ingress cannot route it.
www.example.com/Home/Privacy
Я использую nginx-ingress для маршрутизации трафика.Вход выглядит (с использованием перезаписи)
Код: Выделить всё
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
//...
// I have to use rewrite
nginx.ingress.kubernetes.io/rewrite-target: /$1
//...
spec:
ingressClassName: nginx
rules:
- host: www.example.com
http:
paths:
- backend:
service:
name: dotnet-service
port:
number: 8080
path: /custom/path/?(.*)
pathType: ImplementationSpecific
Код: Выделить всё
Program.csКод: Выделить всё
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.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.Run();
Код: Выделить всё
Views/Shared/_Layout.cshtmlКод: Выделить всё
@* Add below line for setting prefix for href in link tag *@
@* ... *@
[*]
MVPPractice
[list]
Home
[*]
Privacy
[/list]
@* ... *@
@await RenderSectionAsync("Scripts", required: false)
Код: Выделить всё
ASP.NETКод: Выделить всё
/Текущая проблема
- Запрос www.example.com/custom/path/
- Ответ 200
- href — это /Home/Privacy, который ведет на www.example.com/Home/Privacy, он должен быть /custom/path/Home/ Конфиденциальность, чтобы это привело к www.example.com/custom/path/Home/Privacy.
- Нажмите ссылку
- Запросы www.example.com/Home/Privacy< /li>
Ответ 404 (потому что nginx-ingress не может маршрутизировать его)
Подробнее здесь: https://stackoverflow.com/questions/792 ... ngress-rew
Мобильная версия