优化 NGINX 视频服务配置

优化 NGINX 视频服务配置

您好,我已将 VPS 设置为向主站点传输媒体(mp4 视频),此 VPS 仅用于此目的,我的网站托管在不同的 VPS 上。我认为速度有点慢,但目前不是什么大问题,但我想确保这是一个好的配置,因为我对 NGINX 没有很好的经验,并且在网上找到了这个配置,如下所示:

#user  nobody;
worker_processes  6;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    # add proxy caches
    proxy_cache_path /tmp/mycache keys_zone=mycache:70m;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    include /etc/nginx/conf.d/*.conf;
    access_log off;
    sendfile_max_chunk 512k;
    sendfile        on;
    tcp_nopush     on;

    keepalive_timeout  65;

    gzip  on;

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

    server {

        listen 443 ssl http2;
        #listen [::]:80 ipv6only=on;
        root /usr/local/nginx/html;
        index  index.html index.htm;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot

        # Make site accessible from http://localhost/
        server_name example.com;

        location / {
            alias /usr/local/nginx/html;
        }

        location /rtc {
            #try_files $uri $uri/ /index.html;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_pass      http://127.0.0.1:8088/janus;
        }

        location /rtcapp {
            # enable thread pools for livestream
            aio threads=default;

            proxy_pass http://localhost:8188;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
        }
        location ~ \.flv$ {
            # enable thread pool
            aio threads=default;
            flv;
        }

        location /media/ {
            alias /home/my_videos/;
            mp4;
            mp4_buffer_size     1M;
            mp4_max_buffer_size 3M;
            # enable thread bool
            aio threads=default;

            add_header 'Access-Control-Allow-Origin' 'example.com';
            valid_referers none blocked example.com *.example.com;
            if ($invalid_referer) {
                return   403;
            }
            # enable caching for mp4 videos
            proxy_cache mycache;
            proxy_cache_valid 200 300s;
            proxy_cache_lock on;

            # enable nginx slicing
            slice              1m;
            proxy_cache_key    $host$uri$is_args$args$slice_range;
            proxy_set_header   Range $slice_range;
            proxy_http_version 1.1;

            # Immediately forward requests to the origin if we are filling the cache
            proxy_cache_lock_timeout 0s;

            # Set the 'age' to a value larger than the expected fill time
            proxy_cache_lock_age 200s;

            proxy_cache_use_stale updating;

        }

}
}

我的服务器规格是:

AMD EPYC 7282 16-Core Processor
16 GB RAM
400Mbit/s Port
400 GB SSD

我可以编辑任何东西来使其性能更好,或者它已经优化了吗?

相关内容