前台通过nginx连接wildfly13启动的后台(websocket连接),连接不到后台。

前台服务器通过nginx连接wildfly13启动的后台服务器(websocket连接),连接不到后台。服务器之间没有网络因素,换了好多次端口,还是不行,如果不通过Nginx,直接前后台服务器建立连接就可以,求大佬解惑~

1个回答

如果希望使用nginx作为websocket协议的负载均衡,需要单独添加websocket协议支持。正常我们配置的nginx只能支持http协议,应该是这个问题导致的。

    server {
    listen 80;
    server_name xxx.com;
    location /u/ {
        # 反向代理透传客户端ip
        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://127.0.0.1:8001;
        proxy_redirect off;
    }

    location /c/ {
        proxy_pass http://127.0.0.1:8002;
        # WebScoket Support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header Origin xxx;
        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;
    }
}
weixin_37893887
玄尺 tomcat在设置connector使用Http11NioProtocol,就是http1.1。websocket是在1.1基础上扩展(upgrade),必须要指定1.1
一年多之前 回复
qq_24913711
qq_24913711 嗯,我当初配置了websocket那些标签了,昨天突然查到的,是因为我没写proxy_http_version 1.1;这句话,但还是不知道为什么tomcat就可以,可能tomcat有默认参数,wildfly没有吧~
一年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
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"; } } } ``` ```

转到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>

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

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

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 的问题, 求大神帮帮忙!!!

websocket 遇上nginx负载均衡时 error 400

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

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> ```

在AWS Application Load Balancer上使用Go时,WebSocket连接失败并显示301

<div class="post-text" itemprop="text"> <p>I'm trying to run a Go Server with WebSockets on an AWS Application Load Balancer but I am getting an <strong>'Error during WebSocket handshake: Unexpected response code: 301'</strong>. </p> <p>AWS says that The Application Load Balancers supports WebSockets via <strong>ws://</strong> protocols but I can not find any further documentation other than the following:</p> <p>Here's <a href="https://aws.amazon.com/blogs/aws/new-aws-application-load-balancer/" rel="nofollow noreferrer">aws load-balancer link</a></p> <blockquote> <p>The Application Load Balancer supports two additional protocols: WebSocket and HTTP/2.</p> <p>WebSocket allows you to set up long-standing TCP connections between your client and your server. This is a more efficient alternative to the old-school method which involved HTTP connections that were held open with a “heartbeat” for very long periods of time. WebSocket is great for mobile devices and can be used to deliver stock quotes, sports scores, and other dynamic data while minimizing power consumption. ALB provides native support for WebSocket via the ws:// and wss:// protocols.</p> </blockquote> <p>I can get JavaScript to connect to my Go server via WebSockets locally but when I deploy AWS it does not work. This is when the JavaScript displays a 301 error.</p> <p>The Application Load Balancer is listening on <strong>HTTP: 80</strong> and that traffic is being directed to <strong>HTTPS: 443</strong>. All of the Security Groups are pretty much similarly set up to allow traffic through. If I do a normal GET call to retrieve data from my server while deployed on AWS it works perfectly fine.</p> <p>Local call that works to connect to localhost</p> <pre><code>&lt;script&gt; let socket = new WebSocket("ws://localhost:8080/websocket") console.log("Attempting Websocket Connection") socket.onopen = () =&gt; { console.log("Successfully Connected"); socket.send("Hi From the Client!") } socket.onclose = (event) =&gt; { console.log("Socket Closed Connection: ", event) } socket.onmessage = (msg) =&gt; { console.log(msg); } socket.onerror = (error) =&gt; { console.log("Socket Error: ", error) } &lt;/script&gt; </code></pre> <p>Connect to remote server that does not work.</p> <pre><code>&lt;script&gt; let socket = new WebSocket("ws://myexamplesite.com/websocket") console.log("Attempting Websocket Connection") socket.onopen = () =&gt; { console.log("Successfully Connected"); socket.send("Hi From the Client!") } socket.onclose = (event) =&gt; { console.log("Socket Closed Connection: ", event) } socket.onmessage = (msg) =&gt; { console.log(msg); } socket.onerror = (error) =&gt; { console.log("Socket Error: ", error) } &lt;/script&gt; </code></pre> <p>nginx.conf </p> <pre><code>events { worker_connections 1024; } http { server_tokens off; server { listen 80; location / { proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header Host $http_host; proxy_pass http://web:8080/; } } } </code></pre> <p>I expect to be able to establish a WebSocket connection but the following error is returning from the JavaScript file: </p> <p><em>WebSocket connection to 'ws://myexamplesite.com/websocket' failed: Error during WebSocket handshake: Unexpected response code: 301</em></p> </div>

nginx连接超时时的回调机制

我的django通过uwsgi部署在nginx上,现在要从前端上传文件到django进行处理,如果处理的时间过长,nginx会报连接超时的错误;可以通过对nginx进行超时配置来解决,但如果用户从前端上传一个更大的文件,那就需要不断修改这个超时时间,想问有没有一种回调机制,先断开django与nginx的连接,等待django将文件处理完毕后,再通过回调机制调起nginx,将处理结果通过nginx返回到前端

一分钟后,Gorilla WebSocket断开连接

<div class="post-text" itemprop="text"> <p>I'm using Go (Golang) 1.4.2 with Gorilla WebSockets behind an nginx 1.4.6 reverse proxy. My WebSockets are disconnecting after about a minute of having the page open. Same behavior occurs on Chrome and Firefox.</p> <p>At first, I had problems connecting the server and client with WebSockets. Then, I read that I needed to tweak my nginx configuration. This is what I have.</p> <pre><code>server { listen 80; server_name example.com; proxy_pass_header Server; location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forward-Proto $scheme; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_pass http://127.0.0.1:1234; } } </code></pre> <p>My Go code is basically echoing back the client's message. (Errors omitted for brevity). This is my <code>HandleFunc</code>.</p> <pre><code>var up = websocket.Upgrader{ ReadBufferSize: 1024, WriteBufferSize: 1024, } ws, _ := up.Upgrade(resp, req, nil) defer ws.Close() var s struct { Foo string Bar string } for { ws.ReadJSON(&amp;s) ws.WriteJSON(s) } </code></pre> <p>The JavaScript is pretty simple as well.</p> <pre><code>var ws = new WebSocket("ws://example.com/ws/"); ws.addEventListener("message", function(evnt) { console.log(JSON.parse(evnt.data)); }); var s = { Foo: "hello", Bar: "world" }; ws.send(JSON.stringify(s)); </code></pre> <p>Go is reporting <code>websocket: close 1006 unexpected EOF</code>. I know that when I leave or refresh the page <code>ReadJSON</code> returns <code>EOF</code>, but this appears to be a different error. Also, the unexpected EOF happens by itself after about a minute of having the page open.</p> <p>I have an <code>onerror</code> function in JavaScript. That event doesn't fire, but <code>onclose</code> fires instead.</p> </div>

Nginx 后台服务怎么访问nginx中的前端页面

Nginx 后台服务怎么访问nginx中的前端页面; 就是外网部署的是nginx前端页面,内网部署的是后端服务,那么后端服务怎么进入到前端页面呢

Websocket过一小段时间就会自动断开连接

如题... 连接上了之后,过几分钟就会自动断开.. 在多个浏览器测试过...结果都是这样...

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>

即使保持活动状态,Nginx也会关闭连接

<div class="post-text" itemprop="text"> <p>So I have an issues which I'm not sure if it's a GO problem or issues with nginx configuration. Basically when trying to test a curl request to our servers, the connection unexpectedly gets closed, even though keep-alive is set to true. Below is the log I get back from nginx: </p> <pre><code>* About to connect() to sub.domain.com port 80 (#0) * Trying W.X.Y.Z... connected &gt; POST /br HTTP/1.1 &gt; User-Agent: curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3 &gt; Host: sub.domain.com &gt; Accept: */* &gt; Connection: keep-alive &gt; Content-Length: 1635 &gt; Content-Type: application/x-www-form-urlencoded &gt; Expect: 100-continue &gt; &lt; HTTP/1.1 100 Continue &lt; HTTP/1.1 200 OK &lt; Content-Type: application/json; charset=utf-8 &lt; Date: Wed, 31 Aug 2016 15:31:21 GMT &lt; Server: nginx/1.6.1 &lt; Content-Length: 3158 &lt; Connection: keep-alive &lt; {"data1": "some data", "data2": "some data2" .... * Connection #0 to host sub.domain.com left intact * Closing connection #0 ... "dataX": "some dataX", "dataY": "some dataY} </code></pre> <p>Our nginx keep-alive configuration:</p> <pre><code>keepalive_timeout 150; keepalive_requests 5000; </code></pre> <p>The nginx is sitting in front of a Go server, although it shouldn't impact it. Any tips on how to go about trying to figure out why the keep-alive is closing the connection?</p> <p>Edit: complete nginx config:</p> <pre><code>user nginx; worker_processes auto; worker_rlimit_nofile 200000; pid /var/run/nginx.pid; events { worker_connections 60000; multi_accept on; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; error_log /dev/null; access_log /dev/null; sendfile on; tcp_nopush on; keepalive_timeout 150; keepalive_requests 5000; client_header_timeout 2; client_body_timeout 2; reset_timedout_connection on; send_timeout 2; gzip on; include /etc/nginx/conf.d/*.conf; upstream go_app { server 127.0.0.1:3000 weight=1; keepalive 2000; } server { listen 80; server_name 1.domain.com 2.domain.com 3.domain.com 4.domain.com 5.domain.com; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header HOST $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://go_app; proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } } server { listen 80; server_name localhost; root /usr/share/nginx/html; location / { } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } } </code></pre> <p>And the go-code responsible for writing the response:</p> <pre><code>func Success(response http.ResponseWriter, value string) { response.Header().Set("Content-Type", "application/json; charset=utf-8") fmt.Fprint(response, value) response.Write(nil) } </code></pre> </div>

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>..

nginx 某个图片上传时 会出现连接被重置,该如何解决?

nginx 某个图片上传时 会出现连接被重置。服务器查不到访问日志。 input某些文本,偶尔也会出现连接重置的情况。 不知道该如何解决了,测试环境没有问题,正式环境就会出现这种问题。 10次里面会有2、3次上传连接重置的情况。 ![图片说明](https://img-ask.csdn.net/upload/201904/29/1556521501_84394.png)

通过nginx正向代理连接SqlServer数据库的问题

1.内网执行telnet ip 端口 (代理机:例如 10.6.155.99 8088)是通的。 2.代理机执行telnet ip 端口 (网络数据库 221.112.156.98 1433) 也是通的。 3.nginx代理配置代码如下: stream { upstream sqlserver { server 221.112.156.98:1433 max_fails=3 fail_timeout=30s; } server { listen 8088; proxy_connect_timeout 10s; proxy_timeout 600s; proxy_pass sqlserver; } } 4.配置完成后,用navicat测试连接数据库,报错如下: (1).nginx 的日志报错: recv() failed (104: Connection reset by peer) while proxying connection, client: 192.168.1.246, server: 0.0.0.0:8087, upstream: "221.212.156.110:1433", bytes from/to client:0/0, bytes from/to upstream:0/0。 (2)navicat报错如图:![图片说明](https://img-ask.csdn.net/upload/201904/22/1555923585_647790.jpg)

在Alpine上运行nginx

<div class="post-text" itemprop="text"> <p>I would like to run nginx and php-fpm on container start, however I can't seem to do that. Here is my <code>Dockerfile</code>:</p> <pre><code>FROM php:7-fpm-alpine EXPOSE 9080 8000 EXPOSE 9088 80 WORKDIR /var/www COPY . . RUN apk add nginx composer php7-fpm &amp;&amp; \ composer install --no-progress &amp;&amp; \ mkdir -p /etc/nginx /etc/nginx/sites-available /etc/nginx/sites-enabled /run/nginx &amp;&amp; \ ln -s /etc/nginx/sites-available/default.conf /etc/nginx/sites-enabled/default.conf &amp;&amp; \ cp nginx.conf /etc/nginx/conf.d/default.conf CMD ["nginx", "-g", "daemon off;"] </code></pre> <p>Container comes up and running, however when I run <code>ps aux</code> nginx is nowhere to be seen until I run <code>nginx</code> command (configuration is okay, <code>nginx -t</code> returns okay, and running it through open container does start the service). </p> <p>I've tried to chain <code>RUN php-fpm7 &amp;&amp; nginx</code> but that does nothing. </p> <p>Also using entrypoint like <code>ENTRYPOINT ["nginx"]</code> did nothing for me. </p> <p>How can I make sure those processes are running upon creating the container? </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>

linux服务器通过nginx配置正向代理服务器,可以上网启动tomcat连不上数据库

首先描述下我现在的问题: 我在我本地电脑装了一个虚拟机,虚拟机创建了两个linux系统(CentOS6.5),我在一个系统上配置了两个网卡,当做代理服务器,以下简称A机器,另一个系统配置了一个网卡,通过A机器来上网,以下简称B机器,下面简单说下这两个机器的配置情况: A机器:两个网卡,192.168.0.x是外网,通过桥接的方式连接,192.168.176.x内网,通过NAT的方式连接 ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493346575_716608.png) 具体的网络配置: ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493346860_926877.png) ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493346908_744133.png) B机器:一个网卡只有内网地址(192.168.176.129),通过NAT的方式连接, ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493346468_723498.png) 具体的网络配置: ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493346739_754369.png) 另外我是通过nginx做的正向代理,也就是从B到A通过nginx来访问外网,下面看下A机器中nginx配置: ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493347203_702863.png) 目前我把A和B的防火墙都已经关了,在B机器的浏览器中配置了代理,代理如下: ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493347065_767865.png) 我现在的问题是B浏览器可以访问外网,但是我在B中通过命令行ping 192.168.0.249可以ping通,ping192.168.0.38ping不通, 因为0.38是我们数据库的地址,但是现在ping不通,所以我在B中启动tomcat服务器的时候报错,连接数据库超时。 请问现在的问题在哪里,我应该怎么解决呢,我在B中的命令行中已经执行了export http_proxy=http://192.168.176.128:8090这个命令。 补充下A机器的路由列表: ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493360423_781664.png) B机器的路由列表 ![图片说明](https://img-ask.csdn.net/upload/201704/28/1493360430_527374.png)

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

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

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

和黑客斗争的 6 天!

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

点沙成金:英特尔芯片制造全过程揭密

“亚马逊丛林里的蝴蝶扇动几下翅膀就可能引起两周后美国德州的一次飓风……” 这句人人皆知的话最初用来描述非线性系统中微小参数的变化所引起的系统极大变化。 而在更长的时间尺度内,我们所生活的这个世界就是这样一个异常复杂的非线性系统…… 水泥、穹顶、透视——关于时间与技艺的蝴蝶效应 公元前3000年,古埃及人将尼罗河中挖出的泥浆与纳特龙盐湖中的矿物盐混合,再掺入煅烧石灰石制成的石灰,由此得来了人...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

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

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

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

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

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

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

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

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

外包程序员的幸福生活

今天给你们讲述一个外包程序员的幸福生活。男主是Z哥,不是在外包公司上班的那种,是一名自由职业者,接外包项目自己干。接下来讲的都是真人真事。 先给大家介绍一下男主,Z哥,老程序员,是我十多年前的老同事,技术大牛,当过CTO,也创过业。因为我俩都爱好喝酒、踢球,再加上住的距离不算远,所以一直也断断续续的联系着,我对Z哥的状况也有大概了解。 Z哥几年前创业失败,后来他开始干起了外包,利用自己的技术能...

C++11:一些微小的变化(新的数据类型、template表达式内的空格、nullptr、std::nullptr_t)

本文介绍一些C++的两个新特性,它们虽然微小,但对你的编程十分重要 一、Template表达式内的空格 C++11标准之前建议在“在两个template表达式的闭符之间放一个空格”的要求已经过时了 例如: vector&lt;list&lt;int&gt; &gt;; //C++11之前 vector&lt;list&lt;int&gt;&gt;; //C++11 二、nullptr ...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

深入剖析Springboot启动原理的底层源码,再也不怕面试官问了!

大家现在应该都对Springboot很熟悉,但是你对他的启动原理了解吗?

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

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

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

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

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

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

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

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

面试:第十六章:Java中级开发(16k)

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

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

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

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

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

【阿里P6面经】二本,curd两年,疯狂复习,拿下阿里offer

二本的读者,在老东家不断学习,最后逆袭

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

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

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

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

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

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

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

面试官:你连SSO都不懂,就别来面试了

大厂竟然要考我SSO,卧槽。

微软为一人收购一公司?破解索尼程序、写黑客小说,看他彪悍的程序人生!...

作者 | 伍杏玲出品 | CSDN(ID:CSDNnews)格子衬衫、常掉发、双肩包、修电脑、加班多……这些似乎成了大众给程序员的固定标签。近几年流行的“跨界风”开始刷新人们对程序员的...

终于,月薪过5万了!

来看几个问题想不想月薪超过5万?想不想进入公司架构组?想不想成为项目组的负责人?想不想成为spring的高手,超越99%的对手?那么本文内容是你必须要掌握的。本文主要详解bean的生命...

我说我懂多线程,面试官立马给我发了offer

不小心拿了几个offer,有点烦

自从喜欢上了B站这12个UP主,我越来越觉得自己是个废柴了!

不怕告诉你,我自从喜欢上了这12个UP主,哔哩哔哩成为了我手机上最耗电的软件,几乎每天都会看,可是吧,看的越多,我就越觉得自己是个废柴,唉,老天不公啊,不信你看看…… 间接性踌躇满志,持续性混吃等死,都是因为你们……但是,自己的学习力在慢慢变强,这是不容忽视的,推荐给你们! 都说B站是个宝,可是有人不会挖啊,没事,今天咱挖好的送你一箩筐,首先啊,我在B站上最喜欢看这个家伙的视频了,为啥 ,咱撇...

立即提问
相关内容推荐