6

Raspberry Pi 仍在 Apache 2.2 上(现在是 2.2.22-13+deb7u4)。要将 Apache 用作 Websockets 的代理(“ProxyPass”),需要 Apache 模块 mod_proxy_wstunnel。

Apache 模块 mod_proxy_wstunnel 在 httpd 2.4.5 及更高版本中可用。

如何将 mod_proxy_wstunnel 添加到 Raspberry Pi 上的 Apache2 2.2(Backport mod_proxy_wstunnel)?

4

3 回答 3

8

下载 Apache 源代码,从 Vitkin 添加补丁,编译 Apache 并将模块 mod_proxy_wstunnel.so 添加到 Apache 模块

补丁详情:https ://gist.github.com/vitkin/6661683

详细步骤:

# Check apache version (should be 2.2.22 as of writing, if not adjust the next step)
dpkg -s apache2

# Checkout apache source
svn checkout http://svn.apache.org/repos/asf/httpd/httpd/tags/2.2.22/ httpd-2.2.22

# Get patch and apply it
wget https://gist.github.com/vitkin/6661683/raw/873dd8b4de4ad1ff69757ffe48fc574374aedc57/apache-2.2-wstunnel.patch
cd httpd-2.2.22
patch -p1 -i ../apache-2.2-wstunnel.patch

# Build Apache 
svn co http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x srclib/apr
svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x srclib/apr-util
./buildconf # EDIT: Some commenters noted that buildconf should be run before the configure
./configure --enable-proxy=shared --enable-proxy_wstunnel=shared
make

# Copy the module to apache installation
sudo cp modules/proxy/.libs/mod_proxy_wstunnel.so /usr/lib/apache2/modules

# Create module load file
cd /etc/apache2/mods-available
sudo echo "LoadModule proxy_wstunnel_module /usr/lib/apache2/modules/mod_proxy_wstunnel.so" > proxy_wstunnel.load

# Create symbolic link to load the module
cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/proxy_wstunnel.load proxy_wstunnel.load

# Add ProxyPass to Site config
cd /etc/apache2/sites-available

# e.g. modify default site config with "sudo nano default"
# and add the following line inside the VirtualHost element:
# "ProxyPass /websockets/mywebsocket ws://mywebsocketserver.com/websockets/mywebsocket"

# Restart Apache
sudo /etc/init.d/apache2 restart
于 2015-05-25T18:21:33.627 回答
4

对于 CentOS 2.2,我按照这些步骤操作,假设对于 Raspberry Pi,它应该在类似的行上。我已经投入了大量时间来解决这个问题,但可用的文档很少。让我知道这是否有帮助,否则我可以帮助您解决问题。也希望这对未来的读者有所帮助。

要编译mod_proxy_tunnel.so

  1. yum install httpd-devel

  2. 下载mod_proxy_tunnel.c并使用编译它apxs -i -a -c mod_proxy_tunnel.c

然后将上面编译的模块加载到/etc/httpd/modules

  1. 复制mod_proxy_wstunnel.soin /etc/httpd/modules(从上面编译)

  2. 为了在服务器启动时加载模块,请LoadModule在 httpd conf 文件中使用指令/etc/httpd/conf/httpd.conf

    将以下行与所有其他 LoadModule 行一起添加

    LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
    
  3. 重新启动 apache 使用service httpd restart

  4. 重新启动使用后检查 apache 中加载的模块httpd -M

  5. 安装模块后,在 : 中添加这两行/etc/httpd/conf/httpd.conf

    ProxyPass /websockets/mywebsocket ws://mywebsocketserver.com//websockets/mywebsocket retry=4
    ProxyPassReverse /websockets/mywebsocket ws://mywebsocketserver.com//websockets/mywebsocket retry=4
    

注意:确保在默认大小写之前添加上述行/。为了安全起见,还要重新启动apache。

于 2015-07-06T20:59:37.190 回答
3

我需要这个来安装Traccar 站点。我做了一个 apt-update / apt-upgrade。我执行了dpkg -s apache2,这表明我正在运行Version: 2.2.22-13+deb7u7。我开始按照上面 LearningAboutTech 的回答中的说明进行操作。随着时间的流逝,一些过程发生了变化:

  1. 我从apt-get install apache2-threaded-dev开始
  2. 然后我找到了 mod_proxy_wstunnel.c,我使用了这里的版本,并用 wget 获取它
  3. 然后我使用了命令apxs2 -i -a -c mod_proxy_wstunnel.c
  4. 检查配置文件后,我看到模块已经加载到mods-enabled文件夹中。
  5. 我已经在站点配置文件中添加了 ProxyPass 和 ProxyReverse。所以,接下来就是服务 apache2 重启和测试。

测试该站点,它按预期执行,我确实在错误文件中看到了警告:

[警告] 代理:没有协议处理程序对 URL /api/socket 有效。如果您使用的是 DSO 版本的 mod_proxy,请确保代理子模块包含在使用 LoadModule 的配置中。

在某个时候,我会进一步研究这个问题 - 它可能与我刚刚完成的操作或我的设置中的一些其他配置有关 - 但我很高兴我的网站按预期工作!

于 2017-01-24T19:40:59.897 回答