nginx 代理背后的 SpringDoc/Swagger [英] SpringDoc/Swagger behind an nginx proxy

查看:46
本文介绍了nginx 代理背后的 SpringDoc/Swagger的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

We are running a service behind an nginx proxy so that:

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/ 前缀并将请求传递到 /swagger-ui.html 路径上的 post 服务.

When nginx receives request on https://host.com/services/post/swagger-ui.html, it strips the /services/post/ prefix and passes the request to the post service on /swagger-ui.html path.

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

Before setting up anything (with default SpringDoc configuration) I can correctly see the swagger docs on http://service-post:8080/swagger-ui.html.

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

To set the paths for the public address on host.com, I am using:

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

然而,这似乎完全阻止了它:

However it seems that this brakes it completely:

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

/swagger-ui.html, /api-docs and /v3/api-docs/swagger-config return 404 both for service-post:8080/* and https://host.com/services/post/*

唯一似乎有效的是 https://host.com/services/post/swagger-ui/index.html,其中显示了 petstore 文档.

Only thing that seems to work is https://host.com/services/post/swagger-ui/index.html which shows the petstore documentation.

我们没有使用 Spring Boot,只是版本 5.3.1 的 Spring MVC.

We are not using Spring Boot, just Spring MVC of version 5.3.1.

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

So how do I set up to keep the handling of the original paths (eg. /api-docs), but performing the lookup on the prefixed path (/services/post/api-docs)?

推荐答案

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

In the end I completely ignore the default redirect:

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

并实现了我自己的:

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

这样我就不需要改变任何东西,一切都使用默认设置.

This way I don't need to change anything and everything works with default settings.

这篇关于nginx 代理背后的 SpringDoc/Swagger的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆