wandenberg / nginx-push-stream-module

A pure stream http push technology for your Nginx setup. Comet made easy and really scalable.
Other
2.22k stars 295 forks source link

eventsource is not work #91

Closed cnscud closed 11 years ago

cnscud commented 11 years ago

with nginx-pushstream module 0.3.5 release, use your sample conf and example chat.html, the client can't connect to my server, I can't understand why. but your demo is working under http://www.nginxpushstream.com/.

websocket is working fine, stream is working fine, but not eventsource.

thanks.

my configure:

######### push stream ##########################

push_stream_shared_memory_size              100m;
push_stream_max_channel_id_length           200;

# max messages to store in memory
push_stream_max_messages_stored_per_channel  1;

# message ttl
push_stream_message_ttl                      30m;
# ping frequency
push_stream_ping_message_interval           10s;
# connection ttl to enable recycle
push_stream_subscriber_connection_ttl        15m;
# connection ttl for long polling
push_stream_longpolling_connection_ttl        30s;

# broadcast
push_stream_broadcast_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        on;
push_stream_broadcast_channel_max_qtd       3;

push_stream_channel_inactivity_time 60s;

server {

    listen           80;

    #listen          9443 ssl;
    #ssl_certificate     /usr/local/nginx/ssl/server.crt;
    #ssl_certificate_key /usr/local/nginx/ssl/server.key;

    server_name     comet.mydomain.com;

    access_log  /opt/logs/nginx/comet.access.log  main;

    root /opt/webapps/comet;

    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;

        # allow 
        allow 127.0.0.1;
        allow 10.1.0.0/16;
        deny all;

    }

    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;

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

        ### deny all ip for pub???
        allow 127.0.0.1;
        allow 10.1.0.0/16;
        deny all; 
    }

    location ~ /sub/(.*) {
        # activate subscriber mode for this location
        push_stream_subscriber;

        # positional channel path
        set $push_stream_channels_path              $1;

        # header to be sent when receiving new subscriber connection
        push_stream_header_template                 "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-store\">\r\n<meta http-equiv=\"Cache-Control\" content=\"no-cache\">\r\n<meta http-equiv=\"Pragma\" content=\"no-cache\">\r\n<meta http-equiv=\"Expires\" content=\"Thu, 1 Jan 1970 00:00:00 GMT\">\r\n<script type=\"text/javascript\">\r\nwindow.onError = null;\r\ntry{ document.domain = (window.location.hostname.match(/^(\d{1,3}\.){3}\d{1,3}$/)) ? window.location.hostname : window.location.hostname.split('.').slice(-1 * Math.max(window.location.hostname.split('.').length - 1, (window.location.hostname.match(/(\w{4,}\.\w{2}|\.\w{3,})$/) ? 2 : 3))).join('.');}catch(e){}\r\nparent.PushStream.register(this);\r\n</script>\r\n</head>\r\n<body>";

        # message template
        push_stream_message_template                "<script>p(~id~,'~channel~','~text~','~event-id~');</script>";
        #push_stream_message_template                "<script>p(~id~,'~channel~','~text~');</script>";
        # footer to be sent when finishing subscriber connection
        #push_stream_footer_template                 "</body></html>";
        # content-type
        push_stream_content_type                    "text/html; charset=utf-8";

    }

    location ~ /ev/(.*) {
        # activate subscriber mode for this location
        push_stream_subscriber;

        # positional channel path
        set $push_stream_channels_path              $1;

        # activate event source support for this location
        push_stream_eventsource_support on;
    }

    location ~ /lp/(.*) {
        # activate long-polling mode for this location
        push_stream_subscriber      long-polling;

        # positional channel path
        set $push_stream_channels_path    $1;

    }

    location ~ /ws/(.*) {
        # activate websocket mode for this location
        push_stream_websocket;

        # positional channel path
        set $push_stream_channels_path              $1;

        # store messages in memory
        push_stream_store_messages              on;

        # push_stream_websocket_allow_publish     on;
    }

}
cnscud commented 11 years ago

the html is same with http://www.nginxpushstream.org/chat.html , just change modes to "eventsource" first.

wandenberg commented 11 years ago

Which browser you used to test?

cnscud commented 11 years ago

all browsers £ºchrome safari firefox

·¢×Ô iPhone -- Felix Zhang

ÔÚ 2013-7-18£¬22:53£¬Wandenberg Peixoto notifications@github.com дµÀ£º

Which browser you used to test?

¡ª Reply to this email directly or view it on GitHub.

cnscud commented 11 years ago

I compare the 0.3.5 release with the master, not find different. so I can't figure out why not support eventsource , maybe something is wrong with my nginx.

wandenberg commented 11 years ago

Hi Felix, I did a test with your configuration and did not find any problem. Try to set push_stream_authorized_channels_only to off to see if it works. If it works, the only problem is that you are trying to connect to a channel without any message.

cnscud commented 11 years ago

OK, Fixed.

I miss one configuration:
push_stream_allowedorigins ""; under:
location ~ /ev/(._)

Thanks for your concern.