Skip to content

Common NGINX RTMP Live Server Installation Error and How to Resolve It

Daniel Neto edited this page Jul 1, 2024 · 5 revisions

Common NGINX RTMP Live Server Installation Error and How to Resolve It

Overview

There is a common error that occurs during the installation of the NGINX live server, particularly involving SSL and the on_publish parameter. This guide will help you identify and resolve these issues to ensure your live streaming server functions correctly.

Symptoms

  • Your NGINX live server redirects all traffic from HTTP to HTTPS.
  • Live streaming functions are not working correctly.
  • The stats image displays incorrectly, indicating a misconfiguration.

Incorrect Stats Image:

Incorrect Stats Image

Correct Stats Image:

Correct Stats Image

Common Issues and Resolutions

  1. HTTP to HTTPS Redirection

    • Issue: The NGINX server is configured to redirect all HTTP traffic to HTTPS. This is a common misconfiguration.
    • Resolution: The NGINX RTMP server must be configured to work with both HTTP and HTTPS. Ensure that your NGINX configuration allows for both protocols without forced redirection.
  2. on_publish Parameter Misconfiguration

    • Issue: The on_publish parameter and other on_* parameters in the nginx.conf file are set to use HTTPS.
    • Resolution: All on_* parameters in the nginx.conf must use HTTP, not HTTPS. They must not redirect to HTTPS.

Steps to Correct Configuration

  1. Edit NGINX Configuration:

    • Open your nginx.conf file in a text editor.
    • Locate the sections where on_publish and other on_* parameters are defined.
    application live {
        live on;
        on_publish http://localhost/AVideo/plugin/Live/on_publish.php;
        # Other on_* parameters
    }
  2. Ensure HTTP Usage:

    • Make sure all on_* parameters use HTTP.
    on_publish http://localhost/AVideo/plugin/Live/on_publish.php;
  3. Prevent HTTP to HTTPS Redirection:

    • Ensure your server blocks for RTMP and HTTP do not force redirect HTTP traffic to HTTPS.
    server {
        listen 80;
        server_name your-server.com;
    
        location / {
            # No redirection to HTTPS here
        }
    }
  4. Restart NGINX:

    • After making these changes, restart the NGINX server to apply the new configuration.
    sudo /usr/local/nginx/sbin/nginx -s stop && sudo /usr/local/nginx/sbin/nginx

Additional Information

If you access the URL http://localhost/AVideo/plugin/Live/on_publish.php (which could also be your IP address or domain name, depending on your on_publish parameter) directly in your browser, an HTTP error code 401 is expected. This means you did not send the correct credentials. Your RTMP publisher, like OBS, will send the correct credentials to NGINX, which will then forward them to the on_publish script.

  • If the credentials are correct, it will return HTTP code 200, allowing the connection.
  • If your on_publish is correctly configured, when you use the RTMP publisher, you will see some lines in your AVideo logs with the string:
AVideoLog::DEBUG: NGINX ON Publish

Testing the Configuration

To ensure your configuration is correct and the on_publish script is working properly, follow these steps:

  1. Configure OBS:

    • Open OBS.
    • Go to Settings -> Stream.
    • Set the Service to Custom.
    • Set the Server to your RTMP URL (e.g., rtmp://your-server.com/live).
    • Set the Stream Key to your desired stream key.
  2. Start Streaming:

    • Click Start Streaming in OBS.
  3. Check AVideo Logs:

    • Open a terminal on your server.
    • Use the following command to monitor the AVideo logs in real-time and filter for NGINX ON Publish entries:
    tail -f /var/www/html/AVideo/videos/avideo.log | grep -i "NGINX ON Publish"
  4. Verify Log Entries:

    • If your on_publish is correctly configured and the credentials are correct, you should see log entries like:
    AVideoLog::DEBUG: NGINX ON Publish ...
    
  5. Troubleshoot if Necessary:

    • If you do not see any NGINX ON Publish entries in the logs, it means the on_publish request has never reached your server. Double-check your NGINX and OBS configurations.
Clone this wiki locally