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.

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

报告相同问题?

悬赏问题

  • ¥50 关于#html5#的问题:H5页面用户手机返回的时候跳转到指定页面例如(语言-javascript)
  • ¥15 无法使用此凭据登录,因为你的域不可用,如何解决?(标签-Windows)
  • ¥15 yolov9的训练时间
  • ¥15 二叉树遍历没有报错但无法正常运行
  • ¥15 在linux系统下vscode运行robocup3d上场球员报错
  • ¥15 Python语言实验
  • ¥15 SAP HANA SQL 增加合计行
  • ¥20 用C#语言解决一个英文打字练习器,有偿
  • ¥15 srs-sip外部服务 webrtc支持H265格式
  • ¥15 在使用abaqus软件中,继承到assembly里的surfaces怎么使用python批量调动