websocket 遇上nginx负载均衡时 error 400 1C

项目中有一个用websocket实现的即时聊天服务,然后使用nginx做负载均衡服务器之后,websocket便再也无法建立连接,连接报400 bad request ,websocket 和nginx都只是入门,不太懂,求大萝卜指导!!!

2个回答

nginx负载均衡时 error 400 1C
nginx负载均衡bad requestwebsocket
项目中有一个用websocket实现的即时聊天服务,然后使用nginx做负载均衡服务器之后,websocket便再也无法建立连接,连接报400 bad request ,websocket 和nginx都只是入门,不太懂,求大萝卜指导!!!

加配置试试
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
加到 location 里面

    location / {
      proxy_pass http://websocket;
      proxy_pass_header Date;
      proxy_pass_header Server;
      proxy_set_header   Host             $host;
      proxy_set_header   X-Real-IP        $remote_addr;
      proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
django websocket 聊天功能 用nginx代理 访问失败

django 项目 用dwebsocket 实现简单的聊天功能 本地调试已经成功 发布到服务器用nginx做代理, 链接失败 firefox 报错信息: ``` Firefox 无法建立到 ws://xxxxxx/ 服务器的连接。 ``` chrome 报错信息: ``` WebSocket connection to 'ws://xxxxxxx/' failed: Error during WebSocket handshake: Unexpected response code: 400 ``` nginx 配置如下: ``` server { server_name xxxxxxxxxxxxx; listen 80; location /static { root /var/fixpdq; } location /media { root /var/fixpdq; } location / { proxy_pass http://127.0.0.1:8100; proxy_set_header Host $host; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Connection "upgrade"; } } ``` django view 代码如下(多余代码省略了) ``` @require_websocket def chat(request): if request.is_websocket(): print('握手成功') .... ``` 本地调试用127.0.0.1 访问是没问题的, 但在本机用局域网ip访问, 就不通, 发布到服务器, 用nginx做代理, 也是不通, 确定的是前端请求已经到达后台代码了. 我想可能是nginx配置的问题 或者是请求到达服务器nginx之前已然就不是socket请求了(因为本机用局域网ip访问也不通), 但是试过很多方法了, 在view 里request.is_websocket() 这句代码是false, nginx转发后居然不是socket请求了, 那肯定就是nginx的配置问题了, 不应该是django 的问题, 求大神帮帮忙!!!

nginx配置了WebSocket 谷歌浏览器会报404.

用域名访问项目没问题,用域名访问项目WebSocket功能谷歌浏览器就报 WebSocket connection to 'ws://sodb.qdairport.com/qdsodb/websocket/admin' failed: Error during WebSocket handshake: Unexpected response code: 404 用ip加端口访问项目WebSocket功能可以正常连接上 nginx配置文件 #user nobody; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #设置允许上传内容大小 client_max_body_size 200M; client_body_buffer_size 128k; gzip on; #配置域名和ip upstream sodb.qdairport.com { server 10.48.1.16:8080 weight=1; #权重为1 server 10.48.1.17:8080 weight=1; #权重为2 } server { listen 80; server_name sodb.qdairport.com; location / { proxy_pass http://sodb.qdairport.com; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 3; proxy_read_timeout 3600; proxy_send_timeout 60; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } } ``` ```

java的websocket,在负载均衡环境下无法运行

我现在应用里面实现了websocket,用来做扫码登录,现在windows环境下可以正常 运行,正式服务器是linux的centos6.5,负载均衡用的nginx1.8,运行和开发环境都是 jdk8.0和tomcat8.0,启动应用的时候websocket无法正常运行,报400错误,bad request,希望大神协助解决,感激不尽

转到websocket,nginx代理正确吗?

<div class="post-text" itemprop="text"> <p>I have a RESTful server in go, and it's behind nginx. everything is fine and we are happy with this setup (nginx and go) but now we have a websocket route for this application. (Its currently works ok with nginx in our staging server, not real load yet.) The questions :</p> <ol> <li><p>Is this good for my websocket route to be behind nginx too? is there any good reason for/against this? </p></li> <li><p>Is there any way to bypass this route from nginx proxy and serve it directly with go? not in another subdomain or another binary.</p></li> </ol> <p>Thanks!</p> </div>

无法让go.net/websocket在Nginx后面运行

<div class="post-text" itemprop="text"> <p>I'm having trouble getting go.net/websocket to work behind nginx. It works if the application is accessed directly but with nginx, I get an EOF error from Receive.</p> <p>What am I doing wrong?</p> <p>Nginx version: 1.5.10</p> <p>This is my nginx configuration.</p> <pre><code>location /wstest/ { proxy_pass http://localhost:7415/; proxy_http_version 1.1; proxy_set_header Upgrade "websocket"; proxy_set_header Connection "Upgrade"; proxy_buffering off; } </code></pre> <p>Go code:</p> <pre><code>func main() { http.HandleFunc("/", home) http.Handle("/sock", websocket.Handler(pingpong)) http.ListenAndServe(":7415", nil) } func home(w http.ResponseWriter, r *http.Request) { homeTmpl.Execute(w, nil) } func pingpong(conn *websocket.Conn) { var msg string if err := websocket.Message.Receive(conn, &amp;msg); err != nil { log.Println("Error while receiving message:", err) return } if msg == "ping" { websocket.Message.Send(conn, "pong") } } var homeTmpl = template.Must(template.New("home").Parse(` &lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;WS Test&lt;/title&gt; &lt;script&gt; var path = window.location.pathname; var wsURL = "ws://" + window.location.host + path.substring(0, path.lastIndexOf('/')) + "/sock"; var ws; document.addEventListener("DOMContentLoaded", function() { ws = new WebSocket(wsURL); ws.onopen = function() { ws.send("ping"); }; ws.onmessage = function(event) { document.getElementById("status").innerHTML = "Received: " + String(event.data); }; }) &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;span id="status"&gt;Pinging...&lt;/span&gt; &lt;/body&gt; &lt;/html&gt;`)) </code></pre> </div>

Java实现Websocket客户端,Nginx服务器下无法建立连接。是什么原因?

Java实现Websocket客户端,去连接另外一个websocket服务器。 线下测试是可以的。 客户端在tomcat服务器下面 服务端在另外一个tomcat服务器下面 线上无法连接 多了一个ngnix的反向代理 客户端和服务端都在这nigix的代理下面 补充一点:线上ngnix代理下的websocket服务器。通过前端js是可以连接的 只有后端用java进行连接连接不上

转到Nginx Websocket“在收到握手响应之前,连接已关闭”

<div class="post-text" itemprop="text"> <p>I have a Go web server running on my localhost. I'm using Nginx as a reverse proxy to change the protocol to <code>ws</code> when a certain route is accessed on my server.</p> <p>I keep getting this error message in my browser - <code>(index):13 WebSocket connection to 'ws://127.0.0.1:8080/ws' failed: Connection closed before receiving a handshake response</code></p> <p>In addition, the Go server keeps printing this error - <code>read tcp [::1]:8080-&gt;[::1]:59967: read: connection reset by peer</code></p> <p>I've tried a number of combinations in my nginx.conf file. I can't seem to get any of them to work.</p> <p>Go:</p> <pre><code>package main import ( "fmt" "log" "net/http" "github.com/gorilla/websocket" ) func reader(conn *websocket.Conn) { for { messageType, p, err := conn.ReadMessage() if err != nil { log.Println(err) return } fmt.Println(string(p)) if err := conn.WriteMessage(messageType, p); err != nil { log.Println(err) return } } } func homePage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Home Page") } func wsEndpoint(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World") ws, err := websocket.Upgrade(w, r, nil, 1024, 1024) if err != nil { http.Error(w, "Could not open websocket connection", http.StatusBadRequest) log.Println(err) return } log.Println("Client Connected") err = ws.WriteMessage(1, []byte("Hi Client!")) if err != nil { log.Println("Error") log.Println(err) return } reader(ws) } func setupRoutes() { http.HandleFunc("/", homePage) http.HandleFunc("/ws", wsEndpoint) } func main() { fmt.Println("Hello World") setupRoutes() log.Fatal(http.ListenAndServe(":8080", nil)) } </code></pre> <p>index.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8" /&gt; &lt;meta name="viewport" content="width=device-width, initial-scale=1.0" /&gt; &lt;meta http-equiv="X-UA-Compatible" content="ie=edge" /&gt; &lt;title&gt;Go WebSocket Tutorial&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h2&gt;Hello World&lt;/h2&gt; &lt;script&gt; let socket = new WebSocket("ws://127.0.0.1:8080/ws"); console.log("Attempting Connection..."); socket.onopen = () =&gt; { console.log("Successfully Connected"); socket.send("Hi From the Client!"); }; socket.onmessage = msg =&gt; { console.log(msg); }; socket.onclose = event =&gt; { console.log("Socket Closed Connection: ", event); socket.send("Client Closed!"); }; socket.onerror = error =&gt; { console.log("Socket Error: ", error); }; &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>nginx.conf</p> <pre><code> { server { listen 8080; server_name localhost; location /ws { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://localhost:8080/ws; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; } location / { # root html; # index index.html index.htm; proxy_pass http://localhost:8080; } } </code></pre> <p>I'm expecting the websocket connection to stay open indefinitely. I don't know what exactly is closing it and why.</p> <p>Any suggestions on what I'm doing wrong are much appreciated.</p> </div>

django➕dwebsocket➕nginx报错301怎么解决?

最近在做网站的站内消息,使用的django➕dwebsocket➕nginx 但是在上到服务器的时候,访问建立连接的函数,报错301永久重定向了,我nginx也配置了。但是就是连接不上。 ``` nginx配置如下 server { listen 80 default_server; listen [::]:80 default_server; server_name _; # gzip config gzip on; gzip_min_length 1k; gzip_comp_level 9; gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png; gzip_vary on; gzip_disable "MSIE [1-6]\."; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location /api { rewrite ^/api/(.*)$ /$1 break; proxy_pass http://39.97.166.114:8000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 60; proxy_read_timeout 600; proxy_send_timeout 600; } ``` ``` 后台代码 clients = [] @accept_websocket def echo(request): if request.is_websocket: try: clients.append(request.websocket) print(clients) for message in request.websocket: print(message) me = eval(message) # 将字符串类型的消息转换为字典型 print(type(me)) print(me["name"]) me['id']=1 me['username']=2 print(me) # print(request.websocket.count_messages()) if not message: break for client in clients: # print(client.count_messages()) print(client) # print(client.has_messages()) client.send(message) finally: clients.remove(request.websocket) ``` ``` 前端代码 <!DOCTYPE html> <html> <head> <title>django-websocket</title> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script type="text/javascript">//<![CDATA[ $(function () { //创建WebSocket对象获得连接 $('#connect_websocket').click(function () { if(window.websocket){ window.websocket.close() } var websocket = new WebSocket("ws://saas111.com/api/user/echo"); websocket.onopen = function () { console.log('WebSocket open'); }; websocket.onmessage = function (responseData) { console.log('message: ' + responseData.data);//浏览器控制台打印返回的数据 var jsondata = eval('(' + responseData.data + ')'); //将返回的数据转换为json对象 $('#messagecontainer').prepend('<p>' + jsondata.name + '</p>'); //展示数据 }; window.websocket = websocket; }); //发送消息 $('#send_message').click(function () { if(!window.websocket){ alert("Please connect server."); }else{ {# window.s.send($('#message').val());#} //发送字符串数据类型 window.websocket.send(JSON.stringify({"name":$('#message').val()}));//发送json数据类型 } }); //关闭websocket连接 $('#close_websocket').click(function () { if(window.websocket){ window.websocket.close(); } }); }); //]]></script> </head> <body> <br> <input type="text" id="message" value="Hello, World!" /> <button type="button" id="connect_websocket">连接websocket</button> <button type="button" id="send_message">发送消息</button> <button type="button" id="close_websocket">关闭websocket</button> <h1>接收消息</h1> <div id="messagecontainer"> </div> </body> </html> ```

Nginx转发websocket报错 400 bad request 是什么问题,请各位大佬帮忙看看?

端口号8088 1.服务器端代码: @Component @ServerEndpoint("/websocket") public class WebSocket { private Session session; private String name; private static ConcurrentHashMap<String,WebSocket> LinkDeviceMap = new ConcurrentHashMap<>(); private static ConcurrentHashMap<String,WebSocket> LinkPhoneMap= new ConcurrentHashMap<>(); private static CopyOnWriteArraySet<WebSocket> webSockets = new CopyOnWriteArraySet<>(); @OnOpen public void OnOpen(Session session){ this.session = session; webSockets.add(this); System.out.println("[WebSocket] 连接成功"); } @OnClose public void OnClose(){ webSockets.remove(this); System.out.println("[WebSocket] 退出成功"); } @OnMessage public void OnMessage(String message) throws IOException { System.out.println("[WebSocket] 收到的消息"+message); } } } 2.Nginx配置: server { listen 8087; server_name localhost; client_header_buffer_size 16k; large_client_header_buffers 4 256k; # 允许跨域 add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS'; add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization'; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm; proxy_pass http://xxxxxxxxx:8088/websocket; # proxy_pass http://websocket/websocket; #转发 proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } 手机和h5测试ws://xxxxxxxx:8087可以连接websokcet通讯,没有问题,nginx转发websocket没有问题 但是硬件设备和sokit测试工具连接报错400 bad request HTTP/1.1 400 Bad Request..Server: nginx/1.10.3..Date: Thu, 19 Mar 2020 10:37:31 GMT..Content-Type: text/html..Content-Length: 173..Connection: close....<html>..<head><title>400 Bad Request</title></head>..<body bgcolor="white">..<center><h1>400 Bad Request</h1></center>..<hr><center>nginx/1.10.3</center>..</body>..</html>..

小程序开发之搭建WebSocket的WSS环境(Nginx+WorkerMan框架+PHP)

求大神帮忙配置Nginx,由于微信小程序请求WebSocket不能带端口号,需要在Nginx上做一个域名转发(代理) WorderMan端口是8282,主域名用的是80端口,主域名已开启了https Nginx配置文件内容如下: server { listen 80; root /www/web/lsb_abc_net/public_html/public; server_name lsb.abc.net lsb.abc.net; rewrite ^(.*)$ https://$host$1 permanent; index index.html index.php index.htm; error_page 400 /errpage/400.html; error_page 403 /errpage/403.html; error_page 404 /errpage/404.html; error_page 503 /errpage/503.html; location ~ \.php$ { proxy_pass http://127.0.0.1:8282; include naproxy.conf; } location ~ /\.ht { deny all; } location / { try_files $uri @apache; } location @apache { internal; proxy_pass http://127.0.0.1:88; include naproxy.conf; } } server { listen 443; root /www/web/lsb_abc_net/public_html/public; ssl on; ssl_certificate cert/lsb.abc.net.pem; ssl_certificate_key cert/lsb.abc.net.key; ssl_prefer_server_ciphers on; ssl_session_timeout 10m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5; server_name lsb.abc.net; index index.html index.php index.htm; error_page 400 /errpage/400.html; error_page 403 /errpage/403.html; error_page 404 /errpage/404.html; error_page 503 /errpage/503.html; location ~ \.php$ { proxy_pass http://127.0.0.1:88; include naproxy.conf; } location ~ /\.ht { deny all; } location / { try_files $uri @apache; } location @apache { internal; proxy_pass http://127.0.0.1:88; include naproxy.conf; } }

Docker Nginx 502 GET / Post请求的网关不正确,但Websocket无效

<div class="post-text" itemprop="text"> <p>There have been various similar cases here on stackoverflow but they're pretty much all refer to incorrect ports or using localhost as the IP instead of the docker-machine ip.</p> <p>The vue.js app connects perfectly fine to the websocket and works. However, the GET requests to <code>192.168.99.100:8080/meows</code> and other endpoints all hit the <code>nginx 502 bad gateway</code>. Manually accessing the endpoints (instead of vue.js) also hit <code>502 bad gateway</code>.</p> <p>The ip's are properly set. Ports are the same everywhere <code>:8080</code>. endpoints have the correct <code>http verb</code>and all have an <code>nginx upstream</code> pointing at the <code>server location /..{}</code>. Yet no problems connecting to the network, all data passing through no problem.</p> <p>EDIT: Im running windows 7 with the docker-toolbox because my windows version doesnt have the whole virtualization thing. No further configuration after installation has been done.</p> <p>The architecture is the following:</p> <p><a href="https://i.stack.imgur.com/NRVxE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NRVxE.jpg" alt="enter image description here"></a></p> <p>docker-compose</p> <pre><code>version: "3.6" services: meow: build: "." command: "meow-service" depends_on: - "postgres" - "nats" environment: POSTGRES_DB: "meower" POSTGRES_USER: "meower" POSTGRES_PASSWORD: "123456" NATS_ADDRESS: "nats:4222" query: build: "." command: "query-service" depends_on: - "postgres" - "nats" environment: POSTGRES_DB: "meower" POSTGRES_USER: "meower" POSTGRES_PASSWORD: "123456" NATS_ADDRESS: "nats:4222" ELASTICSEARCH_ADDRESS: "elasticsearch:9200" pusher: build: "." command: "pusher-service" depends_on: - "nats" environment: NATS_ADDRESS: "nats:4222" postgres: build: "./postgres" restart: "always" environment: POSTGRES_DB: "meower" POSTGRES_USER: "meower" POSTGRES_PASSWORD: "123456" nats: image: "nats-streaming:0.9.2" restart: "always" elasticsearch: image: 'docker.elastic.co/elasticsearch/elasticsearch:6.2.3' nginx: build: "./nginx" ports: - "8080:80" depends_on: - "meow" - "query" - "pusher" </code></pre> <p>nginx.conf:</p> <pre><code>user nginx; worker_processes 1; events { worker_connections 1024; } http { upstream meows_POST { server meow:8080; } upstream meows_GET { server query:8080; } upstream search_GET { server query:8080; } upstream pusher { server pusher:8080; } server { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; add_header Access-Control-Allow-Origin *; location /meows { limit_except GET POST OPTIONS { deny all; } proxy_pass http://meows_$request_method; } location /search { limit_except GET OPTIONS { deny all; } proxy_pass http://search_GET; } location /pusher { proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://pusher; } } } </code></pre> <p>And to show that the go application also uses the correct ports, the following is the port listening for </p> <pre><code>func newRouter() (router *mux.Router) { router = mux.NewRouter() router.HandleFunc("/meows", listMeowsHandler). Methods("GET") router.HandleFunc("/search", searchMeowsHandler). Methods("GET") return } router := newRouter() if err := http.ListenAndServe(":8080", router); err != nil { log.Fatal(err) } </code></pre> </div>

手机浏览器websocket,无法连接一直error

``` var websocket = null; if ('WebSocket' in window) { websocket = new WebSocket("ws://localhost:8080/springws/websocket/socketServer.do"); } else if ('MozWebSocket' in window) { websocket = new MozWebSocket("ws://localhost:8080/springws/websocket/socketServer.do"); } else { websocket = new SockJS("http://localhost:8080/springws/sockjs/socketServer.do"); } websocket.onopen = onOpen; websocket.onmessage = onMessage; websocket.onerror = onError; websocket.onclose = onClose; ``` 一直是监听到error,请问有了解的吗。 电脑端浏览器是正常的,手机浏览器检测有WebSocket

关于webSocket发生异常的求助

在使用webSocket的时候,发生如下异常,请问这个什么原因造成的? 2019-11-13 09:10:58.048 ERROR 1 --- [http-nio-8080-exec-6] o.a.t.websocket.pojo.PojoEndpointBase : No error handling configured for [com.websocket.WebSocket] and the following error occurred java.io.EOFException: null at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.fillReadBuffer(NioEndpoint.java:1289) at org.apache.tomcat.util.net.NioEndpoint$NioSocketWrapper.read(NioEndpoint.java:1223) at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:72) at org.apache.tomcat.websocket.server.WsFrameServer.doOnDataAvailable(WsFrameServer.java:171) at org.apache.tomcat.websocket.server.WsFrameServer.notifyDataAvailable(WsFrameServer.java:151) at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler.upgradeDispatch(WsHttpUpgradeHandler.java:148) at org.apache.coyote.http11.upgrade.UpgradeProcessorInternal.dispatch(UpgradeProcessorInternal.java:54) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)

JS加载websocket 报错 500 (Internal Server Error)

我用<body onload="initWebSocket()">的方式可以初始化websocket . 但是$(function(){ initWebSocket();})这种方式就会报错. GET http://127.0.0.1/xiangmumingzi/controller/index?bussinessURLPara= 500 (Internal Server Error) 这是什么原因呢. body onload和$(function()有什么区别.jsp页面的加载顺序是怎样的...求大神解答

Nginx发送“连接:关闭”而不是“连接:升级”到Golang后端

<div class="post-text" itemprop="text"> <p>I'm trying to <code>proxy_pass</code> a websocket with Nginx but I'm getting "502 Bad Gateway" and my Golang back end responds: "websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header".</p> <p>Nginx config:</p> <pre><code>server { listen 80; server_name eg.example.com; location / { include proxy_params; proxy_pass http://localhost:8000/; } location ~* /chatclientws/[\w\-]+ { include proxy_params; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; # Added a dummy header to see if Nginx is passing the request properly. proxy_set_header Dummy "Test"; proxy_pass "http://localhost:8000/chatclientws/$1/"; } } </code></pre> <p>Proxy_params:</p> <pre><code>proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-NginX-Proxy true; </code></pre> <p><code>httputil.DumpRequest()</code> in the Golang function for the route produces:</p> <pre><code>GET /chatclientws/13c21679-45b0-424a-872f-aa012a9ee7a0 HTTP/1.0 Host: eg.example.com # Connection says close. Connection: close Accept-Encoding: gzip, deflate Accept-Language: en-US,en;q=0.9,en-GB;q=0.8 Cache-Control: no-cache # Connection says close again. Connection: close Cookie: clientroom=13c21679-45b0-424a-872f-aa012a9ee7a0 Origin: eg.example.com Pragma: no-cache # But websocket request does come through. Sec-Websocket-Extensions: permessage-deflate; client_max_window_bits Sec-Websocket-Key: ykQiDfJ2Tr2Z88WtnBQkAw== Sec-Websocket-Version: 13 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36 X-Forwarded-For: 92.54.215.31 X-Forwarded-Proto: http X-Nginx-Proxy: true X-Real-Ip: 92.54.215.31 </code></pre> <p>Somehow, Nginx is passing down all the information necessary except for the right Connection header.</p> <p>Or so it seems. As seen above, I added a dummy header, <code>proxy_set_header Dummy "Test";</code>, to see if Nginx is really passing the headers down. The dummy header never makes it through.</p> <p>On another page with the same Nginx config but without dynamically generated pathnames, dummy header and websocket connection work well. And, if I hardcode the pathname instead of using regex, like this:</p> <pre><code>location /chatclientws/1a904868-608d-42b2-9e02-4d7d4f8cef19 { ... proxy_pass "http://localhost:8000/chatclientws/1a904868-608d-42b2-9e02-4d7d4f8cef19"; } </code></pre> <p>It works.</p> <p>So, I believe I'm using regex wrongly here. But all the examples I've seen online seem to say my use is ok.</p> <p>I'm puzzled as well as to how the websocket upgrade request comes through. Why is Nginx selectively passing down information?</p> <p>How should I proceed from here?</p> </div>

WebSocket连接失败:连接建立错误:net :: ERR_SSL_PROTOCOL_ERROR

<div class="post-text" itemprop="text"> <p>当我试图通过wss://连接到WebSocket时,我为什么会得到这个错误,但是在ws://上却没问题呢?</p> <h1>错误:</h1> <pre><code>WebSocket connection failed: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR </code></pre> <h1>代码:</h1> <pre><code>package main import ( "fmt" "log" "net/http" //"encoding/json" "github.com/gorilla/websocket" ) var clients map[*websocket.Conn]*Client var upgrader = websocket.Upgrader{ CheckOrigin : func(r *http.Request) bool{ return true }, } type Client struct{ session_id string block_id uint module string } func main(){ var port uint = 8000 http.HandleFunc("/", handleConnections) log.Printf("Websocket server started on: %d", port) err := http.ListenAndServe(fmt.Sprintf(":%d", port), nil) if err != nil { log.Fatal("ListenAndServe: ", err) } } func handleConnections(w http.ResponseWriter, r *http.Request){ // Upgrade initial GET request to a websocket ws, err := upgrader.Upgrade(w, r, nil) if err != nil { log.Print(err) return } defer ws.Close() log.Print("Connection established to IP: ", r.RemoteAddr) ... } </code></pre> </div>

springboot websocket 400错误

本地运行websocket得时候 报400错误 springboot框架 代码如下: 后台配置: ![图片说明](https://img-ask.csdn.net/upload/201910/10/1570686723_607003.jpg) ![图片说明](https://img-ask.csdn.net/upload/201910/10/1570686763_895856.jpg) ![图片说明](https://img-ask.csdn.net/upload/201910/10/1570686812_725115.jpg) 前台调用: ![图片说明](https://img-ask.csdn.net/upload/201910/10/1570686865_776057.jpg) 错误显示: ![图片说明](https://img-ask.csdn.net/upload/201910/10/1570686916_573220.jpg) 一开始我以为是因为传参引起得 把参数去掉也不行 不知道是因为什么情况导致得问题 跪求指点

spring整合websocket出错,Unexpected response code: 404

1. 下面是代码: public class MarcoHandler extends AbstractWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { System.out.println("Received message:"+message.getPayload()); Thread.sleep(2000); session.sendMessage(new TextMessage("Polo!")); } } websocket的xml配置 <websocket:handlers> <websocket:mapping handler="marcoHandler" path="/marco"/> </websocket:handlers> <bean id="marcoHandler" class="com.camle.entity.MarcoHandler"/> web.xml的配置 ``` <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:websocket.xml</param-value> </context-param> ``` javascript代码 <script type="text/javascript"> var url = 'ws://'+window.location.host+'/mvcAndWebsocket/marco'; var sock = new WebSocket(url); sock.onopen = function(){ console.log('Opening'); sayMarco(); }; sock.onmessage = function(e){ console.log('Received message:',e.data); setTimeout(function(){sayMarco()},2000); }; sock.onclose = function(){ alert(window.location.host); console.log('Closing'); }; function sayMarco(){ console.log('Sending Marco!'); sock.send('Marco!'); } </script>

大学四年自学走来,这些私藏的实用工具/学习网站我贡献出来了

大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

Java基础知识面试题(2020最新版)

文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

Linux命令学习神器!命令看不懂直接给你解释!

大家都知道,Linux 系统有非常多的命令,而且每个命令又有非常多的用法,想要全部记住所有命令的所有用法,恐怕是一件不可能完成的任务。 一般情况下,我们学习一个命令时,要么直接百度去搜索它的用法,要么就直接用 man 命令去查看守冗长的帮助手册。这两个都可以实现我们的目标,但有没有更简便的方式呢? 答案是必须有的!今天给大家推荐一款有趣而实用学习神器 — kmdr,让你解锁 Linux 学习新姿势...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

史上最全的 python 基础知识汇总篇,没有比这再全面的了,建议收藏

网友们有福了,小编终于把基础篇的内容全部涉略了一遍,这是一篇关于基础知识的汇总的文章,请朋友们收下,不用客气,不过文章篇幅肯能会有点长,耐心阅读吧爬虫(七十)多进程multiproces...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

新一代神器STM32CubeMonitor介绍、下载、安装和使用教程

关注、星标公众号,不错过精彩内容作者:黄工公众号:strongerHuang最近ST官网悄悄新上线了一款比较强大的工具:STM32CubeMonitor V1.0.0。经过我研究和使用之...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

大学一路走来,学习互联网全靠这几个网站,最终拿下了一把offer

大佬原来都是这样炼成的

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

你期望月薪4万,出门右拐,不送,这几个点,你也就是个初级的水平

先来看几个问题通过注解的方式注入依赖对象,介绍一下你知道的几种方式@Autowired和@Resource有何区别说一下@Autowired查找候选者的...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

立即提问
相关内容推荐