如何将mod_proxy_wstunel添加到Raspberry Pi(Backport mod_proxy_wstunel)上的Apache2 2.2中

如何将mod_proxy_wstunel添加到Raspberry Pi(Backport mod_proxy_wstunel)上的Apache2 2.2中,apache,websocket,raspberry-pi,mod-proxy,apache2-module,Apache,Websocket,Raspberry Pi,Mod Proxy,Apache2 Module,Raspberry Pi仍然在Apache2.2上(现在是2.2.22-13+deb7u4)。 要使用Apache作为WebSocket的代理(“ProxyPass”),需要Apache模块mod_Proxy_wstunnel Apache模块mod_proxy_wstunnel在HTTPD2.4.5及更高版本中提供 如何将mod_proxy_wstunel添加到Raspberry Pi(Backport mod_proxy_wstunel)上的Apache2 2.2中?下载Apache源代码,

Raspberry Pi仍然在Apache2.2上(现在是2.2.22-13+deb7u4)。 要使用Apache作为WebSocket的代理(“ProxyPass”),需要Apache模块mod_Proxy_wstunnel

Apache模块mod_proxy_wstunnel在HTTPD2.4.5及更高版本中提供


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

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

有关修补程序的详细信息:

详细步骤:

# 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

我在CentOS 2.2中遵循了这些步骤,并假设Raspberry Pi应该在类似的行上。我已经花了很多时间来弄清楚这一点,但关于这一点的文档很少。如果这有帮助,请告诉我,否则我可以帮助您解决问题。也希望这对未来的读者有所帮助

要编译
mod\u proxy\u tunnel.so

  • yum安装httpd-devel

  • 下载
    mod_proxy_tunnel.c
    并使用
    apxs-i-a-c mod_proxy_tunnel.c

  • 然后在
    /etc/httpd/modules
    中加载上面编译的模块:

  • 复制
    /etc/httpd/modules
    中的
    mod\u proxy\wstunnel.so
    (从上面编译)

  • 要在服务器启动时加载模块,请在httpd conf文件
    /etc/httpd/conf/httpd.conf

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

    LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
    
  • 要重新启动apache,请使用
    服务httpd restart

  • 要在重新启动后检查apache中加载的模块,请使用
    httpd-M

  • 安装模块后,在
    /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。

    我需要它来安装。我做了apt更新/apt升级。我执行了dpkg-s apache2,这表明我正在运行版本:2.2.22-13+deb7u7。我开始按照中的说明进行操作。 随着时间的推移,一些流程发生了变化:

  • 我从apt get install apache2 threaded dev开始
  • 然后我找到mod_proxy_wstunnel.c,使用该版本,并使用wget获取它
  • 然后我使用命令apxs2-I-a-c mod_proxy_wstunnel.c
  • 在检查了配置文件之后,我看到该模块是 已加载到启用了mods的文件夹中
  • 我已经在站点配置文件中添加了ProxyPass和ProxyReverse。因此,接下来要做的是重新启动apache2服务并进行测试
  • 在测试站点时,它按预期执行,我确实在错误中看到了警告 文件:

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


    在某一点上,我将进一步研究这一点-它可能与我刚才所做的工作或我的设置中的其他一些配置有关-但我很高兴我的网站按预期工作

    当我尝试这个方法时,在“sudo服务apache2重启”之后,我得到了以下结果:apache2:etc/apache2/apache2.conf的第253行出现语法错误/etc/apache2/mods enabled/mod_proxy_wstunnel.load:无法将/usr/lib/apache2/modules/mod_proxy_wstunnel.so加载到服务器:/usr/lib/apache2/modules/modules/mod_proxy_wstunnel.so:未定义的符号:ap_proxy_canonenc–so操作“configtest”失败。有什么想法吗?解决方案是,您不仅要复制mod_proxy_wstunel,还要复制mod_proxy,如图所示:在我的raspbian中,apache版本是2.4.10,但是mod_proxy_wstunel仍然不可用。根据apache文档,它应该在那里。知道为什么吗?echo命令中的输入错误:输出重定向应该是文件名“proxy_wstunnel.load”而不是“mod_proxy_wstunnel.load”@alexmogavero您是否尝试过
    a2enmod proxy_wstunnel.load