dpxyfa4718 2019-02-08 06:53
浏览 155
已采纳

Apache服务器上的websockets的配置文件

I am completely new to backend web development and have made a project using php, but I now want to use websockets to make everything more efficient. To do so, I am going to use Ratchet. I am running Apache 2.4.33. When I attempt to run my test file, I get a 400 error. I do not yet have a server nor a domain and was hoping to run the test files on my local machine. Here is my what user.conf file looks like:

<VirtualHost *:80>
    ServerName localhost

    ProxyPreserveHost On
    ProxyPass / localhost:8080/
    ProxyPassReverse / http:localhost:8080/
    ProxyRequests Off
    RewriteEngine on
    RewriteCond %{HTTP:UPGRADE} ^WebSocket$ [NC]
    RewriteCond %{HTTP:CONNECTION} Upgrade$ [NC]
    RewriteRule .* ws://localhost:8080%{REQUEST_URI} [P]
</VirtualHost>

As I mentioned, whenever I try to run my server.php code, the page comes up as 'HTTP ERROR 400'. There might be issues with my code, but I am fairly certain is has to do with how I set up my conf file.

  • 写回答

1条回答 默认 最新

  • dqyp50298 2019-02-08 21:03
    关注

    There were errors in my config file. I ran apachectl -S to find what they were. Here is the working config file for anyone else struggling with this like I was:

    <Directory "/Users/User/Sites/ProjectFolder">
       AddLanguage en .en
       AllowOverride All
       Options Indexes MultiViews FollowSymLinks
       Require all granted
    </Directory>
    
    ProxyRequests Off
    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://127.0.0.1:8080/$1 [P,L]
    <VirtualHost localhost:8080>
            ProxyPass / ws://localhost:8080/
            ProxyPassReverse / ws://localhost:8080/
    </VirtualHost>
    

    If you are using Ratchet make sure that your composer.json is set up correctly with a valid version. Then upgrade it by running php composer upgrade. Finally, make sure to reset the apache server with sudo apachectl restart.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配