您现在的位置:首页 > 系统运维 > Linux运维

nginx反向代理Flask-SocketIO配置参数

Using nginx as a WebSocket Reverse Proxy

1、使用 nginx 作为 Flask-SocketIO 反向代理

可以将 nginx 用作将请求传递给应用程序的前端反向代理。但是,只有 nginx 1.4 和更新的版本支持 WebSocket 协议的代理。以下是代理 HTTP 和 WebSocket 请求的基本 nginx 配置:
server {
    listen 80;
    server_name _;

    location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:5000;
    }

    location /static {
        alias <path-to-your-application>/static;
        expires 30d;
    }

    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;
    }
}

2、下面示例添加了对多个 Socket.IO 服务器负载平衡的支持:

upstream socketio_nodes {
    ip_hash;

    server 127.0.0.1:5000;
    server 127.0.0.1:5001;
    server 127.0.0.1:5002;
    # to scale the app, just add more nodes here!
}

server {
    listen 80;
    server_name _;

    location / {
        include proxy_params;
        proxy_pass http://127.0.0.1:5000;
    }

    location /static {
        alias <path-to-your-application>/static;
        expires 30d;
    }

    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://socketio_nodes/socket.io;
    }
}
 

版权所有
侵权必究

上一篇
查看 redhat Centos linux 系统版本的方法
下一篇
Linux中awk命令正确的求最大值、最小值、平均值、总和