私は、NginxをSpringブートアプリケーションのリバースプロキシとして使用しています。私はまた、sockjsとstompメッセージとWebsocketを使用します。NginxリバースプロキシWebsocket認証 - HTTP 403
ここにコンテキスト設定があります。ここで
<websocket:message-broker application-destination-prefix="/app">
<websocket:stomp-endpoint path="/localization" >
<websocket:sockjs/>
</websocket:stomp-endpoint>
<websocket:simple-broker prefix="/topic" />
</websocket:message-broker>
は、クライアントのコードです:
var socket = new SockJS(entryPointUrl);
var stompClient = Stomp.over(socket);
var _this = this;
stompClient.connect({}, function() {
stompClient.subscribe('/app/some-url', function (message) {
// do some stuff
});
});
私はまた、あなたは春のセキュリティ一部のコンテンツを保護するために。
@Configuration
@Order(4)
public static class FrontendSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/js/**", "/css/**", "/webjars/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin().loginPage("/login").permitAll()
.and()
.logout().permitAll();
}
}
Nginxリバースプロキシの背後にこのアプリケーションを実行すると、すべてがうまくいきます。
proxy_pass http://testsysten:8080;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# WebSocket support (nginx 1.4)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $http_connection;
# Max body size
client_max_body_size 10M;
接続は常にHTTP 403コードで失敗します。
私はバージョン1.9.7を使用しています。
クライアントが認証されない理由は何ですか?
私はthis oneのような同様の質問を知っていますが、解決策はまったく機能しません。
更新
私はHTTP経由でアプリケーションを実行することができました。 Nginxの設定でCSRFトークンを渡す必要があります。新しい設定は次のとおりです。
HTTPS経由のリダイレクトのみが欠落しています。春のログに次のエントリを参照します
o.s.w.s.s.t.h.DefaultSockJsService - Processing transport request: GET http://testsystem:80/localization/226/3mbmu212/websocket
をnginxのプロキシは、右ポートに書き換える必要があるように思えます。