# websocket location /msg/ { proxy_pass http://172.17.2.71:8888/; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade";
@Slf4j @Configuration @EnableWebSocket public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(myWebSocketHandler(), "/websocket").setAllowedOrigins("*") .addInterceptors(new WebSocketInterceptor()); } @Bean public MyWebSocketHandler myWebSocketHandler() { return new MyWebSocketHandler(); } }
訪問地址為 : ws://IP:port/msg/websocket