nchan_eventsource_ping_comment

The `nchan_eventsource_ping_comment` directive sets an optional ping comment sent to clients during persistent connections for EventSource streaming.

Syntaxnchan_eventsource_ping_comment comment;
Defaultnone
Contextserver, location, if in location
Arguments1

Description

The nchan_eventsource_ping_comment directive is primarily used to ensure that long-lived EventSource connections remain active. When clients are connected to an EventSource stream, the server can send regular ping messages to keep these connections alive, especially in scenarios where idle connections might be dropped by intermediary proxies or clients. By providing a comment through this directive, you can customize what is sent during these pings, helping to maintain the connection while also potentially providing useful information to the client.

The argument for this directive typically accepts a string that serves as the comment. This comment is then included in the server's ping messages. This functionality is particularly important in applications requiring real-time data updates, where maintaining a continuous connection is critical. Depending on the structure of your application and the expected client behavior, tuning this directive can significantly improve the reliability of your EventSource implementations, particularly in environments where network interruptions are common.

This directive can be defined in various contexts such as server, location, or if in location. This flexibility allows for tailored configurations depending on the specific routing of requests in your NGINX setup, permitting differing ping comments for different endpoints as necessary.

Config Example

location /events {
    nchan_eventsource_ping_comment "Ping from server";
    nchan_pubsub;
}

Ensure that the comment does not interfere with the formatting expected by clients.

Using an overly verbose comment could lead to unexpected issues with connection management in some environments.

← Back to all directives