Warm tip: This article is reproduced from serverfault.com, please click

其他-Nginx代理后面的SpringDoc / Swagger

(其他 - SpringDoc/Swagger behind an nginx proxy)

发布于 2020-12-01 13:32:40

我们正在nginx代理后面运行服务,以便:

http://service-post:8080/swagger-ui.html 被路由到公共地址 https://host.com/services/post/swagger-ui.html

或从另一种方式定义:

当nginx在上收到请求时https://host.com/services/post/swagger-ui.html,它会删除/services/post/前缀并将请求传递到路径上的post服务/swagger-ui.html

在设置任何东西之前(使用默认的SpringDoc配置),我可以正确地看到swagger文档http://service-post:8080/swagger-ui.html

要在host.com上设置公共地址的路径,我正在使用:

springdoc.api-docs.path:        /services/post/api-docs
springdoc.swagger-ui.path:      /services/post/swagger-ui.html
springdoc.swagger-ui.configUrl: /services/post/v3/api-docs/swagger-config

但是,似乎这完全制止了它:

/swagger-ui.html/api-docs/v3/api-docs/swagger-config返回404两者的service-post:8080/*https://host.com/services/post/*

似乎唯一起作用的是显示petstore文档的https://host.com/services/post/swagger-ui/index.html

我们不使用Spring Boot,而只是使用5.3.1版的Spring MVC

那么,如何设置以保留对原始路径(例如/api-docs)的处理,但是在前缀路径(/services/post/api-docs上执行查找呢?

Questioner
Vojtěch
Viewed
0
Vojtěch 2020-12-02 19:40:34

最后,我完全忽略了默认重定向:

  • swagger-ui.html ->`swagger-ui / index.html?url = / v3 / api-docs

并实现了我自己的:

  • docs -> swagger-ui/index.html?url=MY_PREFIX/v3/api-docs

这样,我无需进行任何更改,所有设置都可以使用默认设置。