pid         logs/nginx.pid;
error_log    logs/error.log info;

worker_processes    1;

events {
    worker_connections  400000;
    use                 epoll;
}

http {
    include         mime.types;
    default_type    application/octet-stream;

    tcp_nopush                       on;
    #tcp_nodelay                     on;
    keepalive_timeout                20;
    #send_timeout                    10;
    #client_body_timeout             10;
    #client_header_timeout           10;
    sendfile                         on;
    client_header_buffer_size        1k;
    large_client_header_buffers      1 2k;
    client_max_body_size             5k;
    client_body_buffer_size          5k;
    ignore_invalid_headers           on;
    log_format  main   '$remote_addr - $remote_user [$time_local] $request '
                       '"$status" [$request_time $upstream_response_time] $body_bytes_sent "$http_referer" '
                       '"$http_user_agent" "$http_x_forwarded_for"';
    access_log logs/access.log main;
    error_log  logs/error.log info;
    push_stream_shared_memory_size              5000m;
    push_stream_max_channel_id_length            200;
    # max messages to store in memory
    push_stream_max_messages_stored_per_channel  20;
    # message ttl
    push_stream_message_ttl                      5s;
    # ping frequency
    push_stream_ping_message_interval            40s;
    #connection ttl to enable recycle
    #push_stream_subscriber_connection_ttl        9m;
    # connection ttl for long polling
    #push_stream_longpolling_connection_ttl        30m;
    # broadcast
    #push_stream_broadcast_channel_prefix        "broad_";
    push_stream_wildcard_channel_prefix        "broad_";
    #push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\",\"eventid\":\"~event-id~\"}";
    push_stream_message_template                "{\"id\":~id~,\"channel\":\"~channel~\",\"text\":\"~text~\"}";

    # subscriber may create channels on demand or only authorized
    # (publisher) may do it?
    push_stream_authorized_channels_only        off;
    #push_stream_broadcast_channel_max_qtd       3;
    push_stream_wildcard_channel_max_qtd       3;

    server {
#        listen           8080 default_server;
        listen           8080 default_server so_keepalive=on so_keepalive=50:5:3  backlog=8192;
        server_name     localhost;
        
        location ~ /lp/(.*) {
            # activate long-polling mode for this location
            push_stream_subscriber      long-polling;

            # positional channel path
            #set $push_stream_channels_path    $1;
	    push_stream_channels_path    $1;		
            set $push_stream_token       $arg_token;

            push_stream_store_messages              on;
	    push_stream_logserver_report 1;
	    push_stream_logserver_ip	"172.18.0.22";
            push_stream_logserver_port 6019;
	    push_stream_sac_check 1;
            push_stream_sac_ip	"172.18.0.22";
            push_stream_sac_port 7890;
            push_stream_rpc_timeout_ms 1000;
        }

        location ~ /ws/(.*) {
            # activate websocket mode for this location
            #push_stream_websocket;
	    push_stream_subscriber websocket;
            # positional channel path
            #set $push_stream_channels_path              $1;
	    push_stream_channels_path              $1;	
	    set $push_stream_token       $arg_token;
			
            # store messages in memory
            push_stream_store_messages              on;
	    
            push_stream_websocket_allow_publish     on;
	    push_stream_logserver_report 1;
	    push_stream_logserver_ip	"172.18.0.22";
            push_stream_logserver_port 6019;
	    push_stream_sac_check 1;
            push_stream_sac_ip	"172.18.0.22";
            push_stream_sac_port 7890;
            push_stream_rpc_timeout_ms 1000;
            push_stream_redis_report 1;
	    push_stream_redis_ip	"172.18.0.23";
            push_stream_redis_port  6379;
        }
	
    }

    server {
        listen          8094 ssl;
        ssl_certificate      /home/ngxpush/ssl/server.crt;
        ssl_certificate_key  /home/ngxpush/ssl/server.key;
        server_name     localhost;

        location /channels-stats {
            # activate channels statistics mode for this location
            push_stream_channels_statistics;

            # query string based channel id
            #set $push_stream_channel_id             $arg_id;
	    push_stream_channels_path             $arg_id;
        }

        location /pub {
            # activate publisher mode for this location, with admin support
            push_stream_publisher admin;

            # query string based channel id
            #set $push_stream_channel_id             $arg_id;
	    push_stream_channels_path             $arg_id;
	    set $push_stream_msg_id                 $arg_msgid;

            # store messages in memory
            push_stream_store_messages              on;

            #push_stream_keepalive                   on;

            # Message size limit
            # client_max_body_size MUST be equal to client_body_buffer_size or
            # you will be sorry.
            client_max_body_size                    32k;
            client_body_buffer_size                 32k;
        }
        
	    location /nginx_status 
        {
  		    stub_status on;
  		    access_log   off;
  		    allow 172.18.0.0/24;
  		    deny all;
	    }
    }
}
