我有点困惑。我以这种方式在本地启动达芙妮:daphne common.asgi:channel_layer --port 8338
一切都“没问题”。当我使用curl -v 127.0.0.1:8338
得到以下输出
* Rebuilt URL to: 127.0.0.1:8338/
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 8338 (#0)
> GET / HTTP/1.1
> Host: 127.0.0.1:8338
> User-Agent: curl/7.51.0
> Accept: */*
但是当我尝试使用端口分配启动 docker 容器时,并没有说 8338 端口已经被使用:
docker run \
-tid \
-p 8338:8338 \
-v $(PWD):/app \
--network matryoshka_net \
--hostname matryoshka_daphne \
--name matryoshka_daphne \
matryoshka_daphne
在 daphne 已经启动的情况下,运行上面的代码是“好的”。所以在我看来,端口分配不正确。
我错过了什么?
所以这产生了下一个问题,我无法通过 nginx 将信号重定向到 websockets 到我的 docker 容器。因为端口 8338 上没有任何内容(仅启动容器时)。这是 nginx.conf:
server {
listen 127.0.0.1;
gzip on;
gzip_types text/plain application/json text/css application/x-javascript text/javascript application/javascript;
location / {
proxy_set_header Host $host;
proxy_read_timeout 20s;
client_max_body_size 10m;
proxy_pass http://127.0.0.1:8000;
}
location /ws/ {
proxy_pass http://127.0.0.1:8338;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}