Swagger service url behind reverse proxy

Nick Lydon
Aug 18, 2022

This issue was seen in a dotnet application using swashbuckle and swagger-ui.

If you’re deploying apps behind a reverse proxy such as nginx you might find that the service url is incorrect. It may have redirected from http to https for example, leading to the window.location property having the scheme https and the swagger service url having the scheme http. This mismatch will cause the browser to block requests unless CORS response headers are set.

The solution in this case is to use the request headers that have been set by the proxy, which contain the end-url. This document by microsoft details what needs to be changed for dotnet applications.

After that change there’s no need for further configuration. This is transparent to swashbuckle as the request url is updated automatically by the middleware.

--

--

Nick Lydon

British software developer working as a freelancer in Berlin. Mainly dotnet, but happy to try new things! https://github.com/NickLydon