Problem Description: the websocket project was well deployed before. When it was transplanted to the domain name specified by the government cloud SLB, an error occurred:
error during websocket handshake unexpected response code 404
Solution
1. Configure nginx
In any case, configure nginx:
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
location /xxx{
proxy_pass http://127.0.0.1:7071/xxx;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Connection "upgrade";
proxy_set_header Upgrade $http_upgrade;
proxy_connect_timeout 60s;
proxy_read_timeout 7200s;
proxy_send_timeout 600s;
# 再不行的话就把下面的设置试一下
#proxy_set_header Upgrade websocket;
#proxy_pass_request_headers on;
#access_log off;
#proxy_buffering off;
}
2. Websocket configuration
We use springboot, and all configurations cannot be less
import com.fh.websocket.session.MySpringConfigurator;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
/**
* enable WebSocket support
*/
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
@Bean
public MySpringConfigurator mySpringConfigurator() {
return new MySpringConfigurator();
}
}
3. Websocketserver needs to add a parameterless constructor
This is a pit, and it is normal to deploy to another
transplanting will not work in the past.
Read More:
- [Solved] websocket: the client is not using the websocket protocol: ‘upgrade’ token not found in ‘Connection’ head
- [Solved] gnutls_handshake() failed: The TLS connection was non-properly terminated
- [Solved] websocket error in Linux service: / lib64 / libc. So. 6: version ` glibc_2.17‘ not found
- [Solved] svn: OPTIONS of ‘https://xxx/svn/xxx’: SSL handshake failed: SSL error: Key usage violation in certificate has been detected.
- The docker export container cannot be run after being imported: error response from daemon: no command specified
- [Solved] docker: Error response from daemon: OCI runtime create failed: container_linux.go:380
- [docker][issue]Error response from daemon: mkdir xxx: file exists: unknown
- [Solved] Module yaml error: Unexpected key in data: static_context
- Docker pull Command Error response from daemon: Head https://registry-1.docker.io/v2/library/
- [Solved] CUDA initialization: Unexpected error from cudaGetDeviceCount()
- Linux Virtual Machine Boot Container: Error response from daemon: driver failed programming external connectivity on endpoint
- [Solved] Docker Filed to Start Container: Error response from daemon: network XXX not found
- Docker Start Container Error: Error response from daemon: task already exists: unknown
- Shell Script syntax error near unexpected token `done’
- [Solved] Bash: Syntax error: redirection unexpected
- [Solved] Error response from daemon: manifest for nvidia/cuda:latest not found: manifest unknown: manifest
- Ubuntu shell Script syntax error near unexpected token `$‘{\r‘‘
- [Solved] bash: /etc/vimrc: line 15: syntax error near unexpected token `“autocmd“‘
- Ubuntu: How to deal with the fatal: the remote end hung up unexpected error of GIT clone Android kernel
- [Solved] Shell error: syntax error: unexpected end of file