push_stream_subscriber

The `push_stream_subscriber` directive enables a location for subscribing to push stream channels in NGINX.

Syntaxpush_stream_subscriber;
Defaultnone
Contextlocation
Argumentsnone

Description

The push_stream_subscriber directive is part of the NGINX Push Stream Module, which facilitates real-time data streaming over HTTP. When placed in a location block, it configures NGINX to accept subscription requests for push notifications, allowing clients to receive live updates on specified channels. This directive optimizes connections by using protocols such as Comet, EventSource, and WebSocket, enabling various streaming techniques suitable for modern web applications.

When a subscriber connects to a URL that matches the specified location, NGINX establishes a long-lived HTTP connection, where the server can push data to the client as it becomes available. The directive does not require any arguments, but it needs to be used in conjunction with the push_stream_channels_path directive to determine the specific channel from which the subscriber should receive messages. This allows for flexibility in defining channels dynamically based on user input or URL parameters.

It is important to ensure that the push_stream_shared_memory_size directive is properly configured to allocate sufficient shared memory for managing subscriber connections and message buffering. Additionally, operators can enforce limits on the maximum number of subscribers or the maximum messages stored per channel using other related directives, which will help optimize the performance and resource usage of the push stream service.

Config Example

server {
    location ~ /sub/(.*) {
        push_stream_subscriber;
        push_stream_channels_path $1;
    }
}

Ensure that the location block correctly matches subscriber URLs; otherwise, requests will fail.

Avoid excessive connections without proper limits; this can overwhelm server resources.

Keep in mind that the directive should be integrated with shared memory configurations for optimal performance.

← Back to all directives