首页 > 解决方案 > Nginx 反向代理只允许经过身份验证的用户使用 Spring Boot api

问题描述

我的任务是用 Nginx 替换 Zuul 反向代理。Zuul 代理中的安全性是通过implementation 'org.springframework.boot:spring-boot-starter-security'

@EnableWebSecurity
class ZuulSecurity(...) : WebSecurityConfigurerAdapter() {

    override fun configure(http: HttpSecurity) {
        http.csrf().disable().httpBasic().disable()
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER)
                .sessionFixation().changeSessionId()
                .and().authorizeRequests()
                .antMatchers(*dennyPatterns).denyAll()
                .antMatchers(*loginPatterns).permitAll()
                .anyRequest().authenticated()
                .and().formLogin().loginPage(loginUrl)
    }
}

Spring Boot api 服务的保护方式与@EnableWebSecurity

我将 Zuul 反向代理替换为 Nginx 作为反向代理。

如何在 Nginx 上强制执行安全性,以便没有未经身份验证proxy_pass的请求被发送到后端 api 服务?- 换句话说,如果请求是由经过身份验证的用户发出的,我想在 Nginx 上进行验证(loginPatterns url 有一些例外)。我应该学习哪一个nginx/admin-guide/security-controls

标签: javaspringspring-bootnginxspring-security

解决方案



推荐阅读