【问题标题】:Serve springdoc swagger-ui in subdirectory nginx在子目录 nginx 中服务 springdoc swagger-ui
【发布时间】:2022-01-04 22:57:55
【问题描述】:

我已阅读有关如何在反向代理 (https://springdoc.org/index.html#how-can-i-deploy-springdoc-openapi-ui-behind-a-reverse-proxy) 后面提供 springdoc 的文档,并检查了有关该主题的所有问题,但仍有问题。

我正在使用 nginx 在子目录中提供 spring-boot(2.6.2 版本)应用程序:

location /subdirectory/ {
                proxy_pass http://127.0.0.1:8080/;
                proxy_redirect off;
                proxy_buffer_size 128k;
                proxy_buffers 4 256k;
                proxy_busy_buffers_size 256k;

                proxy_set_header Host $http_host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forwarded-Proto https;
                proxy_set_header X-Forwarded-Prefix "/subdirectory/";
                proxy_set_header X-Forwarded-Host $http_x_forwarded_host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-NginX-Proxy true;

                proxy_set_header X-Forwarded-Protocol https;
                proxy_set_header X-Forwarded-Ssl on;
                proxy_set_header X-Url-Scheme https;
        }

我还按照文档配置了 Spring Boot:

application.properties:

server.forward-headers-strategy=framework
server.tomcat.redirect-context-root=false

当我访问我的域以向 Spring Boot API 发出正常请求时,工作正常,例如:

GET https://example.com/subdirectory/countries - OK 200 Returns the expected JSON

但是当我尝试访问 springdoc swagger-ui 时:

GET https://example.com/subdirectory/swagger-ui/index.html - OK 200 

我得到 200 OK,但 .css 和 .js 文件请求返回 404。 我看到一个空白页,没有任何关于 swagger 的信息。我错过了什么吗?

【问题讨论】:

    标签: spring spring-boot nginx swagger-ui springdoc


    【解决方案1】:

    我认为您缺少转发过滤器。

    @Bean
    ForwardedHeaderFilter forwardedHeaderFilter() {
       return new ForwardedHeaderFilter();
    }
    

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 2021-03-13
      • 2020-09-09
      • 1970-01-01
      • 2023-01-15
      • 2023-03-03
      • 2020-06-22
      • 2020-08-04
      • 2021-06-01
      相关资源
      最近更新 更多