将Apache服务器与Engintron一起使用,并且我正在运行一个expressJS应用程序,该应用程序接受socket.io连接来处理websocket调用。
但是,每当主站点(使用PHP)尝试调用nodeJS应用程序时,握手时都会返回错误400,并回退到长时间轮询。
最佳答案
因为我花了很多时间来弄清楚它是如何工作的,所以我认为我会在此处同时张贴问题和答案,因此其他人或我未来的自我不必为此花费无数小时,因为互联网上有很多有关它的信息。
所有的答案都指向我启用mod_proxy_wstunnel,但实际上这并不是我的实际问题。当我禁用Engintron时,我意识到了这一点,并发现它开始起作用。
因此,您需要做的是访问Engintron,转到Edit proxy_params_common
,并确保它看起来像这样:
# /**
# * @version 1.9.3
# * @package Engintron for cPanel/WHM
# * @author Fotis Evangelou (https://kodeka.io)
# * @url https://engintron.com
# * @copyright Copyright (c) 2018 - 2019 Kodeka OÜ. All rights reserved.
# * @license GNU/GPL license: https://www.gnu.org/copyleft/gpl.html
# */
# General Proxy Settings
proxy_pass $PROXY_SCHEME://$PROXY_DOMAIN_OR_IP:$PROXY_TO_PORT;
#proxy_hide_header Upgrade;
proxy_http_version 1.1; # Always upgrade to HTTP/1.1
proxy_set_header Accept-Encoding ""; # Optimize encoding
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; # Enable keepalives
proxy_set_header Host $host;
proxy_set_header Proxy "";
proxy_set_header Referer $http_referer;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $PROXY_FORWARDED_HOST;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header CF-Connecting-IP $http_cf_connecting_ip;
proxy_set_header CF-Visitor $http_cf_visitor;
# Buffers
proxy_buffers 256 16k;
proxy_buffer_size 128k;
proxy_busy_buffers_size 256k;
proxy_temp_file_write_size 256k;
# Timeouts
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
主要区别:
#proxy_hide_header Upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade"; # Enable keepalives