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

时间:2015-05-25 18:21:34

标签: apache websocket raspberry-pi mod-proxy apache2-module

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及更高版本中可用。

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

3 个答案:

答案 0 :(得分:8)

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

有关补丁的详细信息: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

答案 1 :(得分: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

  3. 进行编译

    然后在/etc/httpd/modules

    中加载上面编译的模块
    1. 复制mod_proxy_wstunnel.so /etc/httpd/modules(由上面编译)

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

      将以下行添加到所有其他LoadModule行

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

    4. 重启后使用httpd -M

    5. 检查apache中加载的模块
    6. 安装模块后,在/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
      
    7. 注意:确保在默认情况/之前添加上述行。同时重启apache只是为了安全。

答案 2 :(得分:3)

我需要安装Traccar site。我做了apt-update / apt-upgrade。我执行了 dpkg -s apache2 ,这表明我正在运行版本:2.2.22-13 + deb7u7 。我开始按照LearningAboutTech's answer above中的说明操作。 在过去的时间里,一些过程发生了变化:

  1. 我从 apt-get install apache2-threaded-dev
  2. 开始
  3. 然后我找到了mod_proxy_wstunnel.c,我使用了版本here,并使用wget
  4. 获取了它
  5. 然后我使用了命令 apxs2 -i -a -c mod_proxy_wstunnel.c
  6. 检查配置文件后,我看到模块是 已经加载到 mods-enabled 文件夹中。
  7. 我已经在站点配置文件中添加了ProxyPass和ProxyReverse。所以,接下来就是 service apache2 restart 并测试。
  8. 测试网站,它按预期执行,我确实在错误中看到了警告 文件:

      

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

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

相关问题