mp4

The 'mp4' directive enables MP4 video streaming support in an NGINX location context.

Syntaxmp4;
Defaultnone
Contextlocation
Argumentsnone

Description

The 'mp4' directive is a configuration option in the NGINX HTTP module that allows for the serving of MP4 video files with fast start capabilities. When enabled within a location block, NGINX prepares the MP4 files for playback over HTTP by ensuring that they are streamed efficiently. This is accomplished by placing the necessary metadata at the beginning of the file, allowing the video to begin playing before it has fully downloaded. This directive operates without any arguments and is particularly useful for media applications where smooth playback is a priority.

The 'mp4' directive optimizes the serving of MP4 files by altering how NGINX handles requests for those files. Once activated, NGINX will respond to requests for MP4 formatted files with headers that support the Range request type, allowing clients to request specific byte ranges of the file. This feature is crucial in improving the user experience by minimizing buffering times during video playback. Additionally, it allows seeking within videos, giving users the ability to jump to different timestamps without requiring the entire video to load beforehand.

Config Example

location /videos/ {
    mp4;
    root /var/www/html;
}

Ensure that the MP4 files are encoded correctly to avoid playback issues.

Using the 'mp4' directive alone does not configure additional parameters for buffering or caching which may be necessary for optimal performance.

Remember to set proper MIME types for MP4 files in your server configuration.

← Back to all directives