Docker 中通过 nginx 代理将 flask-socket 事件传递到 uWSGI 服务器的位置
Location for passing flask-socket events to the uWSGI server via nginx proxy in Docker
我正在尝试在 Docker 上将 Socket-IO 事件(基于 Flask-SocketIO)与我的 uwsgi 和 nginx 设置结合使用。我不确定我应该如何配置我的 nginx 文件以允许客户端和服务器之间的套接字连接。这是我当前的 nginx 配置:
server {
listen 80;
server_name _;
location / {
try_files $uri @app;
}
location @app {
include /etc/nginx/uwsgi_params;
uwsgi_pass myapp:8080;
}
location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
uwsgi_pass myapp:8080/socket.io;
}
}
Docker 撰写:
version: '3.5'
services:
web_server:
container_name: nginx
external_links:
- app
build:
context: .
dockerfile: server/Dockerfile
ports:
- 80:80
depends_on:
- app
app:
container_name: myapp
build:
context: .
dockerfile: application/Dockerfile
expose:
- 8080
提前致谢!
Flask-SocketIO 文档显示了一个示例 nginx 配置。这是它的 Socket.IO 位置块:
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5000/socket.io;
}
整个配置为here。
您正在使用 uwsgi_pass,根据我的理解,它不支持代理 WebSocket 连接。如本示例所示使用 HTTP。
我正在尝试在 Docker 上将 Socket-IO 事件(基于 Flask-SocketIO)与我的 uwsgi 和 nginx 设置结合使用。我不确定我应该如何配置我的 nginx 文件以允许客户端和服务器之间的套接字连接。这是我当前的 nginx 配置:
server {
listen 80;
server_name _;
location / {
try_files $uri @app;
}
location @app {
include /etc/nginx/uwsgi_params;
uwsgi_pass myapp:8080;
}
location /socket.io {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
uwsgi_pass myapp:8080/socket.io;
}
}
Docker 撰写:
version: '3.5'
services:
web_server:
container_name: nginx
external_links:
- app
build:
context: .
dockerfile: server/Dockerfile
ports:
- 80:80
depends_on:
- app
app:
container_name: myapp
build:
context: .
dockerfile: application/Dockerfile
expose:
- 8080
提前致谢!
Flask-SocketIO 文档显示了一个示例 nginx 配置。这是它的 Socket.IO 位置块:
location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://127.0.0.1:5000/socket.io;
}
整个配置为here。
您正在使用 uwsgi_pass,根据我的理解,它不支持代理 WebSocket 连接。如本示例所示使用 HTTP。