我对后端 Web 开发完全陌生,并且使用 php 制作了一个项目,但我现在想使用 websockets 来提高一切效率。为此,我将使用 Ratchet。我正在运行 Apache 2.4.33。当我尝试运行我的测试文件时,我收到 400 错误。我还没有服务器也没有域,我希望在我的本地机器上运行测试文件。这是我的 user.conf 文件的样子:
<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>
正如我所提到的,每当我尝试运行 server.php 代码时,页面都会显示为“HTTP ERROR 400”。我的代码可能存在问题,但我相当肯定这与我设置 conf 文件的方式有关。