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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵