【问题标题】:How to add mod_proxy_wstunnel to Apache2 2.2 on Raspberry Pi (Backport mod_proxy_wstunnel)如何在 Raspberry Pi 上将 mod_proxy_wstunnel 添加到 Apache2 2.2 (Backport mod_proxy_wstunnel)
【发布时间】:2015-08-07 06:26:43
【问题描述】:

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)?

【问题讨论】:

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


    【解决方案1】:

    下载 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
    

    【讨论】:

    • 当我尝试这个时,在“sudo service apache2 restart”之后得到以下信息: apa​​che2: /etc/apache2/apache2.conf 的第 253 行的语法错误:/etc 的第 1 行的语法错误/apache2/mods-enabled/mod_proxy_wstunnel.load:无法将 /usr/lib/apache2/modules/mod_proxy_wstunnel.so 加载到服务器中:/usr/lib/apache2/modules/mod_proxy_wstunnel.so:未定义符号:ap_proxy_canonenc – 等等操作配置测试'失败。有什么想法吗?
    • 解决方案是,您不仅要复制 mod_proxy_wstunnel,还要复制 mod_proxy,如下所示:amoss.me.uk/2013/06/…
    • 在我的 raspbian apache 中是 2.4.10 版本,但 mod_proxy_wstunnel 仍然不可用。根据apache文档,它应该在那里。知道为什么吗?
    • 回显命令中的错字:输出重定向应该是文件名“proxy_wstunnel.load”而不是“mod_proxy_wstunnel.load”
    • @alexmogavero 你试过a2enmod proxy_wstunnel.load吗?
    【解决方案2】:

    我在 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. /etc/httpd/modules中复制mod_proxy_wstunnel.so(从上面编译)

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

      在所有其他 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。

    【讨论】:

      【解决方案3】:

      我需要这个来安装Traccar site。我做了一个 apt-update / apt-upgrade。我执行了 dpkg -s apache2,这表明我正在运行 Version: 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。所以,接下来就是service apache2 restart 并进行测试。

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

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

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-10-31
        • 2017-07-06
        • 1970-01-01
        • 1970-01-01
        • 2018-03-22
        • 2015-09-14
        • 2015-02-16
        • 2017-05-08
        相关资源
        最近更新 更多