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 the
Startup.cs
file 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:services.Configure<ForwardedHeadersOptions>(options => { ...