【发布时间】:2018-10-22 08:05:03
【问题描述】:
我正在尝试使用带有 laravel 的棘轮创建视频聊天,它在 localhost 上运行良好,但是当我将它部署到 EC2 实例上时,它需要一些配置。首先,我可以使用 HTTPS 访问我的应用程序,它运行良好。我可以通过 ws 和 HTTP 连接到我的 Ratchet WebSocket 服务器,但 HTTPS 需要 wss,我不知道如何使它工作。我使用了 ProxyPass,因为它似乎是大多数人的答案:(etc/httpd/conf.d/ssl.conf)
ProxyPass /wss2/ ws://fake-domain.us-east-2.elasticbeanstalk.com:8181/
还有我的客户端 JS 代码:var socket = new WebSocket('wss://fake-domain.us-east-2.elasticbeanstalk.com/wss2/');
但这会返回:'WebSocket 握手期间出错:状态行无效' 如果我运行我的 Ratchet 服务器,它甚至不会改变任何东西。
PHP 代码(我设法将它放在 laravel 命令中,这样更容易):
public function handle()
{
$server = IoServer::factory(
new WsServer(
new VideoController()
),
8181
);
$server->run();
}
我可以远程登录 fake-domain.us-east-2.elasticbeanstalk.com 8181,它说可以。 我看到它可能来自 apache 版本,所以我更新了我的 apache 和 php 版本: php -v = 7.2.8 httpd -v = 2.4.34 我接受安全组中的所有流量,并且端口 80、443 和 8181 已打开。
我错过了什么? 谢谢;)
更新:我发现我没有正确启动套接字服务器,我忘记在我的命令前加上“sudo”,但现在它给了我另一个错误:
UnexpectedValueException : $request can not be null
at /var/app/current/vendor/cboden/ratchet/src/Ratchet/WebSocket/WsServer.php:109
105| * {@inheritdoc}
106| */
107| public function onOpen(ConnectionInterface $conn, RequestInterface $request = null) {
108| if (null === $request) {
> 109| throw new \UnexpectedValueException('$request can not be null');
110| }
111|
112| $conn->httpRequest = $request;
113|
更新 2:
我想我刚刚找到了解决方案,我想我没有正确地将 Ratchet 与 Laravel 集成,也许解决方案就在这里:https://gist.github.com/Mevrael/6855dd47d45fa34ee7161c8e0d2d0e88 我明天去试试
【问题讨论】:
标签: javascript php laravel amazon-ec2 websocket