Websocket握手使用engintron返回错误400

时间:2019-04-13 12:00:12

标签: node.js express nginx websocket socket.io

将Apache服务器与Engintron结合使用,并且我正在运行一个expressJS应用程序,该应用程序接受socket.io连接以处理websocket调用。

但是,每当主站点(使用PHP)尝试调用nodeJS应用程序时,握手时都会返回错误400,并回退到长时间轮询。

1 个答案:

答案 0 :(得分:1)

因为我花了很多时间弄清楚它是如何工作的,所以我认为我将在此处同时张贴问题和答案,因此其他人或我未来的自己将不必在此花费很多时间,因为互联网上没有太多信息。

所有答案都指向我启用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