dpxyfa4718 2019-02-08 06:53
浏览 155


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]

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
    ProxyRequests Off
    RewriteEngine On
    RewriteCond %{HTTP:Connection} Upgrade [NC]
    RewriteCond %{HTTP:Upgrade} websocket [NC]
    RewriteRule /(.*) ws://$1 [P,L]
    <VirtualHost localhost:8080>
            ProxyPass / ws://localhost:8080/
            ProxyPassReverse / ws://localhost:8080/

    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++代码报错问题,c++20协程
    • ¥15 c++图Djikstra算法求最短路径
    • ¥15 Linux操作系统中的,管道通信问题
    • ¥15 ansible tower 卡住
    • ¥15 等间距平面螺旋天线方程式
    • ¥15 通过链接访问,显示514或不是私密连接
    • ¥100 系统自动弹窗,键盘一接上就会
    • ¥50 股票交易系统设计(sql语言)
    • ¥15 调制识别中这几个数据集的文献分别是什么?
    • ¥15 使用c语言对日志文件处理