WebSocket 协议是 HTTP 协议的扩展。但是,Apache2 的代理模块似乎并不知道它,并丢弃了关键的标头,将调用转换为标准的 HTTP 调用。
有没有办法让 Apache2 (1) 理解 WebSocket 或 (2) 只是盲目地传递它得到的任何东西?
我们正在尝试设计一种能够处理超过 64k 个 websocket 的架构。
我们首先尝试使用 Amazon ELB,但它的设计不允许意外的流量激增或 websocket。(TCP 模式意外超时 websockets)
使用 HAProxy,这些限制不适用,但我们将被限制在 HA 和后端服务器之间维护的 ~64k websockets。
想到的多种解决方案:
有一个更好的方法吗 ?
domain-name-system scalability load-balancing haproxy websocket
我目前正在尝试在我的个人服务器上运行hack.chat。
长话短说,它由两台服务器组成。第一个是一个简单的 httpd 服务器,提供 javascript 和 CSS。第二个,聊天系统,是一个 node.js 服务器,javascript 使用 websocket 连接到它。问题来了。
我希望全部使用端口 80,在单个 IP 上使用不同的域名,在 Nginx 中使用单独的服务器块。
我遵循了 Nginx websocket 文档,但这不起作用。当 websocket 尝试连接时,它总是得到 200 返回码,而如果我理解得很好,它应该得到 101(切换协议)。
我的 Nginx 版本是 1.8.0,我的服务器在 gentoo 和 linux 4.0.5 上运行
这是相关 nginx conf 文件的转储:
nginx.conf:
user nginx nginx;
worker_processes 1;
error_log /var/log/nginx/error_log info;
events {
worker_connections 1024;
use epoll;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main
'$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" ' …Run Code Online (Sandbox Code Playgroud) 在 Apache 2.4 中,您可以使用以下命令将HTTP连接反向代理到本地Unix套接字:[1]
ProxyPass unix:/path/to/app.sock|http://example.com/app/name
Run Code Online (Sandbox Code Playgroud)
您可以使用以下方法将WebSocket连接反向代理到本地TCP套接字:[2]
ProxyPass ws://127.0.0.1:12345/app/name
Run Code Online (Sandbox Code Playgroud)
但是如何将WebSocket连接反向代理到Unix套接字?[?]
尝试通过我的 Apache2 服务器访问 ws://localhost:8080/ 时出现错误 500。该服务器运行 OpenSuse Leap 42.1 和 Apache 2.4.16。
这些 Apache2 模块已启用:mod_proxy、mod_proxy_http、mod_proxy_wstunnel。
当从本地网络调用请求时,一切正常。网址示例:http://<myhost-ip-address>/api/ws/<some-url>. 它返回状态 101 和响应:Upgrade: websocket。没关系。
来自外网的同类请求失败。网址示例:ws://www.mysite.com/api/ws/<some-url>. 它返回错误 500。
Apache 访问日志包含: GET /api/ws/<some-url> HTTP/1.1" 500 ...
Apache 错误日志包含: [proxy:warn] AH01144: No protocol handler was valid for the URL /api/ws/<some-url>. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.
我的 httpd.conf:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias mysite.com
# Redirection …Run Code Online (Sandbox Code Playgroud) 我依赖的 websocket 库 ( PHP-Websockets ) 尚不支持安全套接字 ( wss)。不过我的网站已经结束https,所以我不能使用不安全的ws连接。
我正在尝试使用Apachemod_proxy将来自浏览器的安全请求转发到客户端。
Javascript
var ws = new Websocket('wss://example.com/_ws_/');
Run Code Online (Sandbox Code Playgroud)
Apache 虚拟主机
ProxyPass "/_ws_/" "ws://127.0.0.1:8080/"
ProxyPassReverse "/_ws_/" "ws://127.0.0.1:8080/"
# I've also tried "/_ws_/" "ws://example.com:8080/" Same error below
Run Code Online (Sandbox Code Playgroud)
尝试连接时,浏览器会收到一个500 Server Error. 日志显示:
没有协议处理程序对 URL /_ws_/ 有效。如果您使用的是 mod_proxy 的 DSO 版本,请确保使用 LoadModule 将代理子模块包含在配置中。
我已经确认,如果我删除代理规则,停止将用户重定向到https并尝试从浏览器连接到不安全的套接字:new Websocket('ws://example.com/'),一切正常。
我加载的 Apache 模块包括mod_ssl.c,mod_proxy.c和mod_proxy_http.c
Apache 2.4
现在有一个应用程序允许人们通过公开一个由Atmosphere提供支持的 AngularJS Web 服务器通过 Web 连接到桌面应用程序。桌面应用程序会公开当前人员的 IP 地址,以便拥有该地址的任何人都可以连接。
我试图通过我的服务器(example.com)代理来掩盖这个 IP。我的服务器目前托管一系列应用程序(Ruby on Rails + Elastic Search、Logstash、Kibana - ELK)并由 Nginx 客户端代理。
我已经设法通过节点 HTTP 代理(本地)成功屏蔽了 IP 地址,现在我正在尝试在使用 Nginx 时使其工作。AngularJS 应用程序使用 Websockets,所以我需要代理 HTTP 和 WS 请求。
我非常接近弄清楚一切。我在没有 Nginx 的情况下进行了本地测试,并且 IP 地址被正确屏蔽。我在让 Nginx 通过同一位置重定向 HTTP 和 Websockets 时遇到了挑战(请参阅代码)。
从所有教程和服务器故障帖子中,我看到 Websockets 通常指向不同的位置,而 Nginx 会优雅地升级连接。
我现在面临一个挑战,我试图通过相同的位置 HTTP/2 和 Websockets 协议进行代理。我已经诉诸邪恶的黑客,例如在location块内使用 IF (但它们没有奏效)。
理想情况下,我希望 Websockets 指向与 HTTP 不同的位置,这将解决问题。我目前的问题是我没有 AngularJS 应用程序的源代码,以便我这样做。
Atmosphere 服务器似乎通过查询参数检测到 Websockets 连接(这是它连接到的 URL):
ws://the-user-ip/?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.3.2-javascript&X-Atmosphere-Transport=websocket&Content-Type=application/json&X-atmo-protocol=true.
Run Code Online (Sandbox Code Playgroud)
这是我当前来自 Nginx 的配置的一部分:
upstream ipmask_docker_app {
server …Run Code Online (Sandbox Code Playgroud) 截至 2 天前,nginx 开始支持 websocket 连接,因此我试图让我的 nginx-nodejs-socket.io 应用程序在没有 HAproxy 等的情况下工作(虽然运气不好)。
我真正想要实现的是 nginx 仅将 websocket 连接请求发送到支持的服务器,或者更准确地说是 websocket 服务器,socket.io,同时 nginx 将提供 php 文件,以及包括 html 文件在内的所有静态内容.我根本不想 express 提供静态内容(如果可能的话)。
这是我的 nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip …Run Code Online (Sandbox Code Playgroud) 我有一个 GCE Ingress 配置并在端口 443 上使用 SSL。我试图让端口 28080 指向我的独立可操作服务器。
我目前为我的 Ingress yaml 准备了这个:
# web-ingress.yaml
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: gke-ingress
annotations:
kubernetes.io/ingress.class: "gce"
ingress.kubernetes.io/ssl-redirect: "true"
kubernetes.io/ingress.allow-http: "false"
spec:
rules:
- host: example.com
http:
paths:
- path: /ws
backend:
serviceName: websocket
servicePort: 28080
tls:
- secretName: gkecert
hosts:
- example.com
backend:
serviceName: web
servicePort: 443
Run Code Online (Sandbox Code Playgroud)
如果我将 websocket 服务的路径设置为 /,它会破坏根路径(错误 503)。从我读过的内容来看,入口无法处理一条路径上的 2 个端口。那么人们如何将他们的前端连接到 websocket 服务器而不用路径分隔呢?
我看到了这个问题,但它似乎对我不起作用。
目前(工作)情况是:
server {
listen 443 ssl;
server_name updates.example.com;
ssl_certificate fullchain.pem;
ssl_certificate_key privkey.pem;
location /update {
proxy_pass "http://localhost:5000";
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_intercept_errors off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Client-Subject $ssl_client_s_dn;
proxy_set_header X-Client-Cert $ssl_client_cert;
}
location / {
proxy_pass "http://localhost:5001";
proxy_connect_timeout 60;
proxy_read_timeout 60;
proxy_send_timeout 60;
proxy_intercept_errors off;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header …Run Code Online (Sandbox Code Playgroud) websocket ×10
nginx ×4
apache-2.4 ×3
mod-proxy ×2
node.js ×2
proxy ×2
apache-2.2 ×1
haproxy ×1
https ×1
kubernetes ×1
mask ×1
proxypass ×1
scalability ×1
socket ×1
ssl ×1