首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么我的Swagger UI在加载到https上时会尝试访问非http内容?

为什么我的Swagger UI在加载到https上时会尝试访问非http内容?
EN

Stack Overflow用户
提问于 2018-08-28 04:45:24
回答 1查看 1.4K关注 0票数 0

我使用的是AWS:ALB,所以我有一个将所有流量转发到特定目标组的规则。当在本地工作时,我能够访问swagger ui页面,而不会因为HTTP而出现问题。当使用HTTPS ALB部署到AWS时,我看到它试图加载一些HTTP内容;这些内容当然会被浏览器阻止。

错误:

代码语言:javascript
运行
复制
Mixed Content: The page at 'https://alb.com/alert/docs/swagger-ui.html' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://alb.com/swagger-resources/configuration/ui'. 
This request has been blocked; the content must be served over HTTPS.

我在项目中的配置中包含以下内容,以便swagger ui可以在/alert/docs/swagger-ui.html下加载:

代码语言:javascript
运行
复制
@Configuration
@EnableWebMvc
@ComponentScan
public class DocumentationConfig extends WebMvcConfigurerAdapter {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/alert/docs/v2/api-docs", "/v2/api-docs");
        registry.addRedirectViewController("/alert/docs/configuration/ui", "/configuration/ui");
        registry.addRedirectViewController("/alert/docs/swagger-resources/configuration/ui", "/swagger-resources/configuration/ui");
        registry.addRedirectViewController("/alert/docs/swagger-resources/configuration/security", "/swagger-resources/configuration/security");
        registry.addRedirectViewController("/alert/docs/configuration/security", "/configuration/security");
        registry.addRedirectViewController("/alert/docs/swagger-resources", "/swagger-resources");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/alert/docs/**").addResourceLocations("classpath:/META-INF/resources/");
    }
}

我是否遗漏了导致这种情况发生的任何配置?

EN

回答 1

Stack Overflow用户

发布于 2019-03-14 20:29:34

如果您使用的是SpringBoot,则可以添加以下内容:

代码语言:javascript
运行
复制
server:
    tomcat:
        remote-ip-header: x-forwarded-for
        protocol-header: x-forwarded-proto`

发送到您的application.yaml或application.properties。更多详情请点击这里:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-security.html#howto-enable-https

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52046730

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档