Using Nginx or Apache on Linux
Publishing an ASP.NET Core application on Linux looks very similar to the way it looks on IIS, but preparing it for the reverse proxy requires some additional steps. You will need a web server such as Nginx or Apache as a reverse proxy that forwards the traffic to Kestrel and the ASP.NET Core application:
- First, you need to allow your app to accept two specific forwarded headers. To do this, open
Startup.cs
and add the following lines to theConfigure
method before theUseAuthentication
middleware:app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });
- You also need to trust the incoming traffic from the reverse proxy. This requires you to add the following lines to the
ConfigureServices
method:Builder.Services.Configure<ForwardedHeadersOptions>( options => { ...