18

I've been working on a Perl Mojolicious project that uses websockets. I'm wanting to launch it on a shared server running apache and use proxyPass and proxyPassReverse to make the url prettier for my Mojolicious code running with Hypnotoad.

I have it set up as follows.

Apache url:

mydomain.com

Hypnotoad url:

mydomain.com:8080

With the following apache entry I can reverse proxy the Hypnotoad server to

project.mydomain.com

apache.conf entry

<VirtualHost *:80>
  ServerName project.mydomain.com
  DocumentRoot /var/www/project
  <Directory /var/www/project/>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order allow,deny
    allow from all
  </Directory>
  ProxyRequests Off
  ProxyPreserveHost On
  ProxyPass / http://mydomain.com:8080/ keepalive=On
  ProxyPassReverse / http://mydomain.com:8080/
  RequestHeader set X-Forwarded-HTTPS "0"
</VirtualHost>

However my websocket requests give a 404 error when I use:

ws://project.mydomain.com/get-data

and a 302 error when I use:

ws://mydomain.com:8080/get-data

I guess this wouldn't be a problem is the websocket didn't check for authentication, but they use Mojolicious routes to check that you can post via the websocket.

From what I can see Apache doesn't support reverse proxying websockets. In apache/httpd conf files.

Has anyone found a usable solution to this using Apache that is stable for a production environment?

4

3 回答 3

16

3 月,Jim Jagielski向 Apache 主干提交了一个补丁,该补丁允许正确代理 websocket。该补丁添加了一个名为 proxy_wstunnel 的新子模块,它允许 mod_proxy 使用“ws”和“wss”协议

该模块尚未出现在任何官方 Apache 版本中(截至 2013 年 6 月 8 日),因此您需要自己编译它。Voyageur 的博客描述了 Apache 2.2 的过程,但 Apache 2.4 应该更容易

于 2013-06-08T10:39:31.563 回答
15

Apache httpd 2.4.6 包括代理 websocket 请求。

于 2013-08-08T14:11:35.280 回答
-5

这可能是您正在寻找的。看看:https ://npmjs.org/package/npr

于 2013-06-21T03:52:07.300 回答