I use Nginx as the reverse proxy for the Spring boot application. I also use Websockets with sockjs and stomp messages.
Here is the contextual configuration.
<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>
Here is the client code:
var socket = new SockJS(entryPointUrl); var stompClient = Stomp.over(socket); var _this = this; stompClient.connect({}, function () { stompClient.subscribe('/app/some-url', function (message) {
I also give you Spring Security to protect some content.
@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(); } }
Everything works fine, expect when I run this application behind the Nginx reverse proxy. Here is the reverse configuration:
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;
The connection is always with HTTP code 403.
I am using version 1.9.7.
Do you have any ideas why the client is not receiving authentication?
I know similar questions like this one , but solutions do not work at all.
Update
I managed to run the application through HTTP. I need to pass the CSRF token in the Nginx configuration. New configuration:
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;
Only there is no redirection over HTTPS. Spring logs display the following entry:
oswssthDefaultSockJsService - Processing transport request: GET http://testsystem:80/localization/226/3mbmu212/websocket
It seems that Nginx Proxy needs to be rewritten to the right port.