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

问题描述 投票:6回答:3

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?

apache websocket raspberry-pi mod-proxy apache2-module
3个回答
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

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.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检查apache中加载的模块
  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只是为了安全起见。


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. 然后我找到了mod_proxy_wstunnel.c,我使用了版本here,并用wget获取了它
  3. 然后我使用命令apxs2 -i -a -c mod_proxy_wstunnel.c
  4. 检查配置文件后,我看到模块已经加载到mods-enabled文件夹中。
  5. 我已经在站点配置文件中添加了ProxyPass和ProxyReverse。所以,接下来就是服务apache2重启和测试。

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.