中阅读更多信息
无法使用Docker容器连接WebSocket
我docker-compose.yml:
`
version: "2"
services:
db:
image: mysql
ports:
- 3306:3306
volumes:
- "./.data/db:/var/lib/mysql"
environment:
MYSQL_ROOT_PASSWORD: "qwerty"
MYSQL_DATABASE: "web_face"
MYSQL_USER: "web_face"
MYSQL_PASSWORD: "qwerty"
php:
build: php7-fpm
ports:
- 9000:9000
- 3333:3333
links:
- db:mysqldb
volumes:
- ../www/:/var/www/symfony
- ../logs/symfony:/var/www/symfony/app/logs
- ../logs/php:/data/log/phpfpm/
nginx:
build: nginx
ports:
- 80:80
links:
- php
volumes_from:
- php
volumes:
- ../logs/nginx/:/var/log/nginx
但是当我试图连接Rachet Websocket服务器时,我有错误:WebSocket连接'ws://127.0.0.1/'失败:WebSocket握手时错误:意外响应码:200
您是否更改了nginx配置以正确处理websocket握手?
您需要类似于以下的配置:
server {
listen 80;
upstream websocket {
server php:9000;
}
location / {
proxy_pass http://websocket;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
}
你可以在nginx文档