Skip to content
Extraits de code Groupes Projets
Valider fc696f4d rédigé par aftys's avatar aftys
Parcourir les fichiers

updated nginx conf

parent fcb3efcd
Branches
Aucune requête de fusion associée trouvée
#!/bin/bash
# Exit immediately if a command exits with a non-zero status
set -e
# Update the apt package index
sudo apt-get update
# Install packages to allow apt to use a repository over HTTPS
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
# Add Docker's official GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# Set up the stable repository
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# Update the apt package index again
sudo apt-get update
# Install the latest version of Docker CE and containerd
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
# Install Docker Compose
sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")')" -o /usr/local/bin/docker-compose
# Apply executable permissions to the Docker Compose binary
sudo chmod +x /usr/local/bin/docker-compose
# Add the current user to the docker group
sudo usermod -aG docker $USER
# Print Docker version
docker --version
# Print Docker Compose version
docker-compose --version
echo "Docker and Docker Compose have been installed successfully. Please log out and log back in to apply the Docker group changes."
......@@ -2,27 +2,33 @@ daemon off;
error_log /dev/stdout info;
worker_processes auto; # Automatically set worker processes based on CPU cores
events {
worker_connections 4096; # Augmenter le nombre de connexions de travail
worker_connections 4096; # Increase worker connections for handling more clients
use epoll;
multi_accept on;
}
rtmp {
server {
listen 1935;
chunk_size 8192; # Augmenter la taille des chunks pour améliorer les performances
allow publish all;
application live {
live on;
record off;
hls on;
hls_path /tmp/hls;
hls_fragment 1; # Réduire la taille des fragments pour une latence plus faible
hls_playlist_length 5; # Réduire la longueur de la playlist pour une latence plus faible
hls_fragment_naming system;
hls_fragment_naming_granularity 2;
hls_fragment_slicing aligned;
server {
listen 1935;
chunk_size 8192; # Increase chunk size for better throughput
application live {
live on;
record off;
# HLS settings
hls on;
hls_path /dev/shm/hls; # Use a memory-based path for HLS
hls_fragment 1; # Short fragment size for lower latency
hls_playlist_length 10; # Increase playlist length for better buffering
hls_fragment_naming system;
hls_fragment_naming_granularity 2;
hls_fragment_slicing aligned;
}
}
}
}
http {
......@@ -35,18 +41,35 @@ http {
keepalive_timeout 65;
types_hash_max_size 2048;
gzip on; # Enable gzip compression
gzip on;
gzip_types text/plain application/xml application/json text/css application/javascript;
server {
listen 443 ssl;
server_name hls.mydressin-server.com;
ssl_certificate /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /dev/shm; # Ensure root matches the memory-based HLS path
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *; # Allow all origins
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS'; # Allow specific methods
add_header Access-Control-Allow-Headers '*'; # Allow all headers
expires -1;
}
location /dash {
root /tmp;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
expires -1; # Désactiver la mise en cache pour les fichiers HLS
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
add_header Access-Control-Allow-Headers '*';
expires -1;
}
location /stat {
......@@ -59,14 +82,41 @@ http {
}
location /control {
rtmp_control all;
add_header Access-Control-Allow-Origin * always;
}
rtmp_control all;
add_header Access-Control-Allow-Origin * always;
}
location / {
root html;
index index.html index.htm;
}
}
}
server {
listen 80;
server_name hls.mydressin-server.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl;
server_name status.mydressin-server.com;
ssl_certificate /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
location / {
proxy_pass http://localhost:3003;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
server {
listen 80;
server_name status.mydressin-server.com;
return 301 https://$server_name$request_uri;
}
}
......@@ -163,4 +163,4 @@ async function getViewerCount(streamKey) {
}
}
module.exports = { startRecording, stopRecording, getViewerCount }
module.exports = { startRecording, stopRecording, getViewerCount }
\ No newline at end of file
#!/bin/bash
# Set up error handling
set -e
# Update the package list and install required dependencies
sudo apt update
# Install build dependencies for nginx and nginx-rtmp-module
sudo apt install -y build-essential git zlib1g-dev libpcre3 libpcre3-dev libssl-dev ffmpeg nodejs npm openssl
# Directory to store the build files
BUILD_DIR="/tmp/nginx-rtmp-build"
# Create the build directory
mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
# Clone the necessary repositories
git clone https://github.com/arut/nginx-rtmp-module.git
git clone https://github.com/nginx/nginx.git
# Build nginx with the RTMP module
cd nginx
./auto/configure --add-module=../nginx-rtmp-module --with-http_ssl_module
make
sudo make install
# Install nginx modules (pcre, etc.) and create necessary directories
sudo mkdir -p /usr/local/nginx/html
sudo mkdir -p /usr/local/nginx/conf/ssl
sudo mkdir -p /tmp/hls
sudo mkdir -p /tmp/dash
# SSL Setup: Copy SSL certificates to nginx SSL directory (replace with your actual certificate path)
sudo cp ./PositiveSSL_Wildcard_mydressin-server.com.pem /usr/local/nginx/conf/ssl/
# Configure optimized nginx.conf
sudo bash -c "cat > /usr/local/nginx/conf/nginx.conf" << 'EOF'
daemon off;
error_log /dev/stdout info;
events {
worker_connections 8192;
use epoll;
multi_accept on;
}
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
# HLS settings
hls on;
hls_path /tmp/hls;
hls_fragment 3s;
hls_playlist_length 18s;
hls_fragment_naming system;
hls_fragment_naming_granularity 2;
hls_fragment_slicing aligned;
# HLS bitrate variants
hls_variant _low BANDWIDTH=800000;
hls_variant _mid BANDWIDTH=1200000;
hls_variant _high BANDWIDTH=2400000;
# DASH settings
dash on;
dash_path /tmp/dash;
dash_fragment 3s;
dash_playlist_length 18s;
# Reduce CPU usage
meta copy;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
gzip on;
gzip_comp_level 5;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
application/atom+xml
application/javascript
application/json
application/ld+json
application/manifest+json
application/rss+xml
application/vnd.geo+json
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/bmp
image/svg+xml
image/x-icon
text/cache-manifest
text/css
text/plain
text/vcard
text/vnd.rim.location.xloc
text/vtt
text/x-component
text/x-cross-domain-policy;
server {
listen 443 ssl;
server_name hls.mydressin-server.com;
ssl_certificate /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
ssl_certificate_key /usr/local/nginx/conf/ssl/PositiveSSL_Wildcard_mydressin-server.com.pem;
location /hls {
types {
application/vnd.apple.mpegurl m3u8;
}
root /tmp;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
expires -1;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/html;
}
location /control {
rtmp_control all;
add_header Access-Control-Allow-Origin * always;
}
location / {
root html;
index index.html index.htm;
}
}
server {
listen 80;
server_name hls.mydressin-server.com;
return 301 https://$server_name$request_uri;
}
}
EOF
# Expose necessary ports (80 for HTTP, 443 for HTTPS, and 1935 for RTMP)
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 1935
# Setup Node.js app
# Install npm packages and PM2 (Process Manager for Node.js)
sudo npm install
sudo npm install pm2 -g
# Expose Node.js port (3003)
sudo ufw allow 3003
sudo chmod +x ./start.sh
# Make the script executable
# Start Nginx and Node.js app
sudo ./start.sh
# Clean up the build directory
echo "Setup complete. Nginx with RTMP, SSL, and Node.js are running."
......@@ -4,5 +4,5 @@
/usr/local/nginx/sbin/nginx &
# Start the Node.js app
node /app/server.js
node ./register-live-api/server.js
0% ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter