nginx代理后面的spring boot swagger2-找不到swagger资源

我的pom:

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger2</artifactId>
    <version>2.9.2</version>
</dependency>
<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-swagger-ui</artifactId>
    <version>2.9.2</version>
</dependency>

和大张旗鼓的配置文件

@Configuration
@EnableSwagger2
@EnableWebMvc
@Profile("stage")
public class SwaggerConfig {
    @Bean
    public Docket api() {
        HashSet<String> protocols = new HashSet<>();
        protocols.add("http");
        protocols.add("https");
        return new Docket(DocumentationType.SWAGGER_2)
                .protocols(protocols)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .pathMapping("/");
    }
    @Bean
    public WebMvcConfigurer webMvcConfigurer()
    {
        return new WebMvcConfigurer()
        {
            @Override
            public void addResourceHandlers( ResourceHandlerRegistry registry )
            {
                registry.addResourceHandler( "swagger-ui.html" ).addResourceLocations( "classpath:/Meta-INF/resources/" );
                registry.addResourceHandler( "/webjars/**" ).addResourceLocations( "classpath:/Meta-INF/resources/webjars/" );
            }
        };
    }
}

当我在工作站上访问/swagger-ui.html时,一切正常,但是当我在舞台环境中运行此项目时,其中我的nginx代理具有设置:

location ~ ^/(swagger|webjars|configuration|swagger-resources) {
  proxy_pass https://backend;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection 'upgrade';
  proxy_set_header Host $host;
  proxy_cache_bypass $http_upgrade;
}

我的招摇页面正在加载,但收到警报

  

无法推断基本网址。这在使用动态servlet时很常见   注册或API位于API网关后面。基本网址是   服务所有招摇资源的根。例如如果   可以在http://example.org/api/v2/api-docs获得api,然后   基本网址是http://example.org/api/。请输入位置   手动:

当我检查发出的网络请求时,我可以发现后端返回了404找不到 / swagger-resources / configuration / security

/ swagger-resources

/ swagger-resources / configuration / ui

有任何提示吗?

j_lieying 回答:nginx代理后面的spring boot swagger2-找不到swagger资源

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3165655.html

大家都在问