-
Notifications
You must be signed in to change notification settings - Fork 977
Common NGINX RTMP Live Server Installation Error and How to Resolve It
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.
- 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:
Correct Stats Image:
-
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.
-
on_publish
Parameter Misconfiguration-
Issue: The
on_publish
parameter and otheron_*
parameters in thenginx.conf
file are set to use HTTPS. -
Resolution: All
on_*
parameters in thenginx.conf
must use HTTP, not HTTPS. They must not redirect to HTTPS.
-
Issue: The
-
Edit NGINX Configuration:
- Open your
nginx.conf
file in a text editor. - Locate the sections where
on_publish
and otheron_*
parameters are defined.
application live { live on; on_publish http://localhost/AVideo/plugin/Live/on_publish.php; # Other on_* parameters }
- Open your
-
Ensure HTTP Usage:
- Make sure all
on_*
parameters use HTTP.
on_publish http://localhost/AVideo/plugin/Live/on_publish.php;
- Make sure all
-
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 } }
-
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
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
To ensure your configuration is correct and the on_publish
script is working properly, follow these steps:
-
Configure OBS:
- Open OBS.
- Go to
Settings
->Stream
. - Set the
Service
toCustom
. - Set the
Server
to your RTMP URL (e.g.,rtmp://your-server.com/live
). - Set the
Stream Key
to your desired stream key.
-
Start Streaming:
- Click
Start Streaming
in OBS.
- Click
-
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"
-
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 ...
- If your
-
Troubleshoot if Necessary:
- If you do not see any
NGINX ON Publish
entries in the logs, it means theon_publish
request has never reached your server. Double-check your NGINX and OBS configurations.
- If you do not see any