晴明的博客园 GitHub      CodePen      CodeWars     

[nginx] socket转发

ngx_stream_core_module

The ngx_stream_core_module module is available since version 1.9.0. This module is not built by default, it should be enabled with the --with-stream configuration parameter. (不过貌似window不需要手动启)

events {
    worker_connections  1024;
}


http {
    ......
}

stream {
    # 添加socket转发的代理
    upstream qm_socket {
        hash $remote_addr consistent;
        # 转发的目的地址和端口
        server 114.80.166.240:3333 weight=5 max_fails=3 fail_timeout=30s;
        # max_fails=3  失败后尝试重连3次
        # fail_timeout=30s  3次都失败后,再次进行3次重连的间隔
    }

    # 提供转发的服务,即访问localhost:3222,会跳转至代理 qm_socket 指定的转发地址
    server {
       listen 3222;
       #proxy_connect_timeout 1s;
       #proxy_timeout 180s;  #不支持直接设置分钟。不设置的话貌似默认时间是30m?
       proxy_pass qm_socket;
    }
}
posted @ 2017-05-08 18:50  晴明桑  阅读(302)  评论(0编辑  收藏  举报