nginx WebSocket握手返回错误400与engintron

4zcjmb1e  于 2023-08-03  发布在  Nginx
关注(0)|答案(1)|浏览(125)

使用Apache服务器与Engintron,我有一个expressJS应用程序运行,它接受socket.io连接来处理WebSocket调用。
但是,每当主站点(PHP)尝试调用nodeJS应用程序时,它会在握手时返回错误400,并福尔斯长轮询。

iklwldmw

iklwldmw1#

因为我花了很多时间来弄清楚这是如何工作的,我想我应该把问题和答案都贴在这里,所以其他人,或者我未来的自己不必花无数的时间在这上面,因为互联网上没有太多关于它的信息。
所有的答案都指向我启用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

相关问题