Reputation: 2297
I am running a spring boot micro-serivce within my docker container running as a kubernetes pod.
The swagger UI runs fine when the spring boot application is run locally.
When deployed in to our kubernetes cluster, we are fronting it with nginx which proxies the requests to the pod.
I am struggling to figure out how to make swagger UI work with nginx.
Things I tried so far
In my "ssl.conf" i tried adding the following;
location ~ ^/(webjars.*) {
rewrite ^/(.*)$ /$1 break;
proxy_pass https://gw-test-request:443;
}
location ~ ^/(gw.*) {
rewrite ^/(.*)$ /swagger-ui.html break;
proxy_pass https://$1:443;
}
Note that the second location has a prefix for how we have named our micro-service modules with a prefix of gw.
With this, it tries to load swagger when I enter https:///gw-test but then silently fails. It does not load everything that it does when I tried locally as I observed the network requests that go through.
The network calls I see when it works locally;
The network calls I see when it is behind nginx;
Any help would be greatly appreciated.
** Edit **
The 404s displayed on the last screenshot turned out to be 200s but it still does not load the swagger UI.
** Edit **
The swagger configuration being used;
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
ApiInfo apiInfo = new ApiInfo(
"<>",
"<>",
"<>",
"<>",
new Contact("<>", "<>", "<>"),
"N/A",
"N/A",
new ArrayList<>());
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("<rest controller base package>"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo);
}
}
Upvotes: 1
Views: 5164
Reputation: 1741
This usually happens when the security protocol in your swagger configuration is not configured to allow https, the default protocol only allows http connections so you have to explicitly set the protocol to include https
In your swagger configuration, add the following lines
.protocols(newHashSet("http", "https"));
This should fix your problem.
Upvotes: 4