Springfox swagger html无法使用apache反向代理

时间:2018-03-27 03:22:51

标签: apache spring-boot swagger reverse-proxy springfox

我的swagger-ui.html文件正确地显示在我的本地开发环境中的春季启动应用程序中。但是,当我使用Apache部署我的应用程序时,它不起作用。我猜我的apache配置可能有误。非常感谢任何帮助。

在我的httpd.conf文件中,我有:

ProxyPass /myAppSwagger http://localhost:8081/swagger-ui.html ProxyPassReverse /myAppSwagger http://localhost:8081/swagger-ui.html

这是我的招摇配置:

@Configuration
@EnableSwagger2
public class SwaggerConfig {                                    
    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(Predicates.not(RequestHandlerSelectors.basePackage("org.springframework.boot")))              
          .paths(PathSelectors.any())                          
          .build().directModelSubstitute(Timestamp.class, Long.class);
    }


}

这样会招摇这样的招摇: enter image description here

1 个答案:

答案 0 :(得分:0)

我能够解决我的问题。原来我的apache httpd.conf错了。 一旦我修复了我的apache配置的VirtualHost部分,swagger就能够加载所有需要的资源。

感谢Ataur Ra​​hman Munna指出我正确的方向。我需要编辑httpd.conf以打开" ProxyPreserveHost"并修复我的ProxyPass和ProxyPassReverse值,只是指向我的应用程序的根目录,而不是swagger-ui.html。

*注意: 为了到达我的休息端点,我使用

http://myapUrl/myApp

要使用我的招摇文件

http://myappUrl/myAppSwagger/swagger-ui.html

我没有必要更改任何代码才能使其正常工作,只需编辑我的apache httpd.conf文件即可获得此内容,使其成功:

<VirtualHost *:80> ProxyRequests Off ProxyPreserveHost On ProxyPass /myApp http://localhost:8081/myApp ProxyPassReverse /myApp http://localhost:8081/myApp ProxyPass /myAppSwagger http://localhost:8081/ ProxyPassReverse /myAppSwagger http://localhost:8081/
</VirtualHost>

有关Enabling the Apache ProxyPreserveHost directive

的信息,请参阅此处