我們有一個 Spring boot 應用程序,在服務器上部署了 Spring security。我們使用 https,但是當重定向到 Spring 默認登錄表單時,會使用 http 調用重定向,這會導致 503 服務不可用。我不明白為什么Spring要切換通信協議,有沒有辦法阻止它?我們的配置protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/", "/home", "/status", "/actuator").permitAll() .anyRequest().authenticated() .and() .formLogin() .permitAll() .and() .logout() .permitAll() .and() .csrf() .disable();}要重定向的頁面:登錄 :
2 回答

繁華開滿天機
TA貢獻1816條經驗 獲得超4個贊
這是一個代理問題,我只需在我的 application.properties 中添加以下行
server.tomcat.remote-ip-header=x-forwarded-for server.tomcat.protocol-header=x-forwarded-proto

呼啦一陣風
TA貢獻1802條經驗 獲得超6個贊
嘗試顯式啟用HSTS:
protected void configure(HttpSecurity http) throws Exception {
? ? http
? ? ? ? .headers()
? ? ? ? ? ? .hsts()
? ? ? ? .authorizeRequests()
? ? ? ? ? ? .antMatchers("/", "/home", "/status", "/actuator").permitAll()
? ? ? ? ? ? .anyRequest().authenticated()
? ? ? ? ? ? .and()
? ? ? ? .formLogin()
? ? ? ? ? ? .permitAll()
? ? ? ? ? ? .and()
? ? ? ? .logout()
? ? ? ? ? ? .permitAll()
? ? ? ? ? ? .and()
? ? ? ? .csrf()
? ? ? ? ? ? .disable();
}
添加回答
舉報
0/150
提交
取消