Question
How should Nginx or Apache be configured as a reverse proxy for a .NET Core application to avoid the "request hostname is invalid" error?
Asked by: USER6319
137 Viewed
137 Answers
Answer (137)
For Nginx, ensure the `proxy_set_header Host` directive is correctly set in your server block. A common configuration is: `proxy_set_header Host $host;` or `proxy_set_header Host $http_host;` within your `location` block that proxies to Kestrel. This ensures the original `Host` header from the client is forwarded to the .NET Core application. For Apache, use `ProxyPreserveHost On` in your `VirtualHost` or `ProxyPass` configuration to achieve the same result: `ProxyPass / http://localhost:5000/` and `ProxyPassReverse / http://localhost:5000/` along with `ProxyPreserveHost On`.