Next, you’ll need to activate this new configuration. Nginx’s convention is to create symbolic links (like shortcuts) from files in sites-available/ to another folder called sites-enabled/ as you decide to enable or disable them. Using full paths for clarity, make that link:
command berikut untuk set dapat di akses oleh spesifik ip
inally, to access the statistics page that you added, you will need to open another port in your firewall. Specifically, the listen directive is configured with port 8080, so you will need to add a rule to access Nginx on that port. However, you probably don’t want others to be able to access your stats page, so it’s best only to allow it for your own IP address. Run the following command:
sudo ufw allow from your_ip_address to any port http-alt
sudo systemctl reload nginx.service
Creating Modern Streams for Browsers
As a final step, you may want to add support for newer streaming protocols so that users can stream video from your server using a web browser directly. There are two protocols that you can use to create HTTP-based video streams: Apple’s HLS and MPEG DASH. They both have advantages and disadvantages, so you will probably want to support both.
The Nginx-RTMP module supports both standards. To add HLS and DASH support to your server, you will need to modify the rtmp block in your nginx.conf file. Open /etc/nginx/nginx.conf using nano or your preferred editor, then add the following highlighted directives:
sudo nano /etc/nginx/nginx.conf
. . .
rtmp {
server {
. . .
application live {
live on;
record off;
hls on;
# -- addd this command -- #
hls_path /var/www/html/stream/hls;
hls_fragment 3;
hls_playlist_length 60;
dash on;
dash_path /var/www/html/stream/dash;
# -- addd this command -- #
}
}
}
. . .
# Adding Monitoring to Your Configuration 💯 👍
- [digitalocean](https://www.digitalocean.com/community/tutorials/how-to-set-up-a-video-streaming-server-using-nginx-rtmp-on-ubuntu-22-04#step-4-adding-monitoring-to-your-configuration-optional) :
```
sudo nano /etc/nginx/sites-available/rtmp
```
- insert command :
```
server {
listen 8080;
server_name localhost;
# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /var/www/html/rtmp;
}
# rtmp control
location /control {
rtmp_control all;
}
}
```
- Create the /var/www/html/rtmp directory, and then uncompress the stat.xsl.gz `file tersebut tersedia di module rtmp` file with the following commands:
```
sudo mkdir /var/www/html/rtmp
sudo gunzip -c /usr/share/doc/libnginx-mod-rtmp/examples/stat.xsl.gz > /var/www/html/rtmp/stat.xsl
```
- Next, you’ll need to activate this new configuration. Nginx’s convention is to create symbolic links (like shortcuts) from files in sites-available/ to another folder called sites-enabled/ as you decide to enable or disable them. Using full paths for clarity, make that link:
```
sudo ln -s /etc/nginx/sites-available/rtmp /etc/nginx/sites-enabled/rtmp
```
```
sudo ufw allow 8080/tcp
sudo systemctl reload nginx.service
```
- command berikut untuk set dapat di akses oleh spesifik ip
inally, to access the statistics page that you added, you will need to open another port in your firewall. Specifically, the listen directive is configured with port 8080, so you will need to add a rule to access Nginx on that port. However, you probably don’t want others to be able to access your stats page, so it’s best only to allow it for your own IP address. Run the following command:
```
sudo ufw allow from your_ip_address to any port http-alt
```
```
sudo systemctl reload nginx.service
```
# Creating Modern Streams for Browsers
As a final step, you may want to add support for newer streaming protocols so that users can stream video from your server using a web browser directly. There are two protocols that you can use to create HTTP-based video streams: Apple’s HLS and MPEG DASH. They both have advantages and disadvantages, so you will probably want to support both.
The Nginx-RTMP module supports both standards. To add HLS and DASH support to your server, you will need to modify the rtmp block in your nginx.conf file. Open /etc/nginx/nginx.conf using nano or your preferred editor, then add the following highlighted directives:
```
sudo nano /etc/nginx/nginx.conf
```
```
. . .
rtmp {
server {
. . .
application live {
live on;
record off;
hls on;
# -- addd this command -- #
hls_path /var/www/html/stream/hls;
hls_fragment 3;
hls_playlist_length 60;
dash on;
dash_path /var/www/html/stream/dash;
# -- addd this command -- #
}
}
}
. . .
```
- edit file rtmp
```
sudo nano /etc/nginx/sites-available/rtmp
```
- add command
```
. . .
server {
listen 8088;
# -- addd this command -- #
location / {
add_header Access-Control-Allow-Origin *;
root /var/www/html/stream;
}
# -- addd this command -- #
......
}
# -- addd this command -- #
types {
application/dash+xml mpd;
}
# -- addd this command -- #
```
```
sudo mkdir /var/www/html/stream
```
```
sudo systemctl reload nginx
```
- open video
http://your_domain:8088/hls/stream.m3u8
or
http://your_domain:8088/dash/stream.mpd
You should now have an HLS stream available at http://your_domain:8088/hls/stream.m3u8 and a DASH stream available at http://your_domain:8088/dash/stream.mpd. These endpoints will generate any necessary metadata on top of your RTMP video feed in order to support modern APIs.
Adding Monitoring to Your Configuration 💯 👍
file tersebut tersedia di module rtmpfile with the following commands:command berikut untuk set dapat di akses oleh spesifik ip
inally, to access the statistics page that you added, you will need to open another port in your firewall. Specifically, the listen directive is configured with port 8080, so you will need to add a rule to access Nginx on that port. However, you probably don’t want others to be able to access your stats page, so it’s best only to allow it for your own IP address. Run the following command:
Creating Modern Streams for Browsers
As a final step, you may want to add support for newer streaming protocols so that users can stream video from your server using a web browser directly. There are two protocols that you can use to create HTTP-based video streams: Apple’s HLS and MPEG DASH. They both have advantages and disadvantages, so you will probably want to support both.
The Nginx-RTMP module supports both standards. To add HLS and DASH support to your server, you will need to modify the rtmp block in your nginx.conf file. Open /etc/nginx/nginx.conf using nano or your preferred editor, then add the following highlighted directives:
http://your_domain:8088/hls/stream.m3u8
or
http://your_domain:8088/dash/stream.mpd
You should now have an HLS stream available at http://your_domain:8088/hls/stream.m3u8 and a DASH stream available at http://your_domain:8088/dash/stream.mpd. These endpoints will generate any necessary metadata on top of your RTMP video feed in order to support modern APIs.