【问题标题】:Spring security behind Apache reverse proxy [duplicate]Apache反向代理背后的Spring安全[重复]
【发布时间】:2022-01-22 17:51:16
【问题描述】:

我的 Spring-boot 应用程序位于 Apache 代理后面。 我的应用程序正在处理http,与 SSL 相关的任务由代理服务器处理。

我正在使用 Spring-security 的登录页面。 以下是我的安全配置:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.cors();

        http.authorizeRequests()
                .antMatchers("/admin/**").hasAuthority("Admin")
                .anyRequest().permitAll()
                .and()
                .formLogin()
                .defaultSuccessUrl("/admin", true);

    }

因此,作为具有管理员权限的人成功登录,我重定向到 /admin。 在我使用 apache 代理之前,这一切正常。

在使用代理之前它工作正常。

( http://myhost/login >> 成功登录后重定向到 >> http://myhost/admin )

使用代理后:

( https://myhost/login >> 成功登录后重定向到 >> http://myhost/admin )

主要问题是它重定向到http 而不是https

下面是我的 apache 代理配置:

ProxyPreserveHost on
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

我的问题是如何在登录后重定向到https

任何帮助将不胜感激!!!

【问题讨论】:

    标签: java spring-boot apache spring-security reverse-proxy


    【解决方案1】:

    我对 Apache 代理设置的经验有限,但根据我的理解,您需要启用 SSLEngine 以支持 SSL 协议:

    文档:

    SSLEngine 指令

    Description:    SSL Engine Operation Switch
    Syntax: SSLEngine on|off|optional
    Default:    SSLEngine off
    Context:    server config, virtual host
    Status: Extension
    Module: mod_ssl
    

    该指令切换 SSL/TLS 协议引擎的使用。这 is 应该在一个部分中使用以启用 SSL/TLS 那个虚拟主机。默认情况下,SSL/TLS 协议引擎是 对主服务器和所有配置的虚拟主机都禁用。

    示例

    <VirtualHost _default_:443>
    SSLEngine on
    #...
    </VirtualHost>
    

    在 Apache 2.1 及更高版本中,SSLEngine 可以设置为可选。这 启用对 RFC 2817 的支持,在 HTTP/1.1 中升级到 TLS。在 这次没有网络浏览器支持 RFC 2817。

    https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#page-header

    【讨论】:

      猜你喜欢
      • 2019-06-13
      • 2017-01-23
      • 2017-07-09
      • 2017-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-04-14
      • 2017-10-14
      • 2019-03-14
      相关资源
      最近更新 更多