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

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.

主站蜘蛛池模板: 固阳县| 永清县| 抚州市| 竹山县| 普定县| 库尔勒市| 慈溪市| 浙江省| 德保县| 安远县| 扶沟县| 郧西县| 绍兴县| 佛坪县| 北票市| 咸宁市| 泸西县| 灵丘县| 玛沁县| 桑植县| 若羌县| 南通市| 桃江县| 连州市| 石河子市| 沙田区| 吴堡县| 桂林市| 同江市| 远安县| 仙游县| 富顺县| 鄯善县| 恩平市| 定边县| 福安市| 边坝县| 扬州市| 简阳市| 汪清县| 泸西县|