Inc33
Inc33

Reputation: 1921

Websocket handshake returns error 400 with engintron

Using Apache server with Engintron, and I have an expressJS app running, that accepts socket.io connections to handle websocket calls.

But whenever the main site (in PHP) tries to make a call to the nodeJS app, it returns error 400 at handshake, and falls back to long polling.

Upvotes: 1

Views: 424

Answers (1)

Inc33
Inc33

Reputation: 1921

Because I've spent so much time figuring out how this works, I thought I'd post both, the question and answer here, so others, or my future self won't have to spend countless hours on this, as there wasn't much information about it on the internet.

All the answers were pointing me to enabling mod_proxy_wstunnel, but when in fact that wasn't my actual problem. I realized this, when I disabled Engintron, and found out that it started working.

So what you need to do, is access Engintron, go to Edit proxy_params_common, and make sure it looks something like this:

# /**
#  * @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;

key differences:

#proxy_hide_header             Upgrade;
proxy_set_header              Upgrade $http_upgrade;
proxy_set_header              Connection "upgrade";      # Enable keepalives

Upvotes: 2

Related Questions