官术网_书友最值得收藏!

  • NGINX Cookbook
  • Tim Butler
  • 152字
  • 2021-07-03 00:04:29

How it works....

There's only one main block directive to get our simple test working, with a few key areas.

proxy_pass http://127.0.0.1:3000; 

The proxy will forward the connection back to our Express-driven test application, which we configured to listen on port 3000 of the localhost.

proxy_http_version 1.1; 

By default, proxied connections back to the Node.js application will be HTTP/1.0 only. Setting this to HTTP/1.1 allows the use of keep-alive, which means the connection between NGINX and the application remains open rather than establishing a new connection every time. On a heavily loaded system, this is much more efficient.

proxy_set_header Upgrade $http_upgrade; 
proxy_set_header Connection "upgrade"; 

The WebSocket protocol uses the Upgrade and Connection headers as part of the handshake process. We need to set this at the NGINX level in order to allow the handshake process to work as expected. As it's compatible with HTTP/1.1, it won't interfere with the standard connections either.

主站蜘蛛池模板: 香港 | 清镇市| 建水县| 锦屏县| 信宜市| 沂水县| 贺兰县| 宣城市| 上虞市| 绥芬河市| 铜梁县| 唐海县| 嵊州市| 郧西县| 大名县| 溧水县| 陆丰市| 陇西县| 廊坊市| 界首市| 金堂县| 广州市| 遂昌县| 万全县| 昭通市| 西华县| 乾安县| 晋州市| 和静县| 天等县| 南昌市| 吉林省| 万全县| 天峨县| 长兴县| 镇安县| 遂溪县| 农安县| 华蓥市| 盐源县| 慈溪市|