我使用的是AWS:ALB,所以我有一个将所有流量转发到特定目标组的规则。当在本地工作时,我能够访问swagger ui页面,而不会因为HTTP而出现问题。当使用HTTPS ALB部署到AWS时,我看到它试图加载一些HTTP内容;这些内容当然会被浏览器阻止。
错误:
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下加载:
@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/");
}
}我是否遗漏了导致这种情况发生的任何配置?
发布于 2019-03-14 20:29:34
如果您使用的是SpringBoot,则可以添加以下内容:
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
https://stackoverflow.com/questions/52046730
复制相似问题