FastDFS+FastDHT 外网访问视频

在只配置外网 ip 端口映射的情况下,图片,excel 文件等可以正常访问,访问视频时提示连接被重置。

下载 nginx 视频模块

wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz

下载 openssl

https://www.openssl.org/

下载 nginx

http://nginx.org/en/

上传文件到 /usr/local 目录下

[root@fastdfsdht local]# ls
nginx_mod_h264_streaming-2.2.7.tar.gz  openssl-1.1.1h.tar.gz               
nginx-1.19.3.tar.gz      fastdfs-nginx-module                   

删除已安装的 nginx

删除之前备份一下 /usr/local/nginx/conf/nginx.conf 文件

[root@fastdfsdht conf]# cp /usr/local/nginx/conf/nginx.conf /tmp/nginx.conf.bak
[root@fastdfsdht conf]# /usr/local/nginx/sbin/nginx -s stop
[root@fastdfsdht conf]# find / -name nginx
/run/nginx
/var/log/nginx
/var/temp/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
[root@fastdfsdht conf]# rm -rf /run/nginx
[root@fastdfsdht conf]# rm -rf /var/log/nginx
[root@fastdfsdht conf]# rm -rf /var/temp/nginx
[root@fastdfsdht conf]# rm -rf /usr/local/nginx
[root@fastdfsdht conf]# rm -rf /usr/local/nginx/sbin/nginx

[root@fastdfsdht local]# tar -zxvf nginx_mod_h264_streaming-2.2.7.tar.gz
[root@fastdfsdht local]# tar -zxvf  openssl-1.1.1h.tar.gz
[root@fastdfsdht local]# tar -zxvf  nginx-1.19.3.tar.gz
[root@fastdfsdht local]# ls
nginx_mod_h264_streaming-2.2.7  nginx_mod_h264_streaming-2.2.7.tar.gz
openssl-1.1.1h  nginx-1.19.3  openssl-1.1.1h.tar.gz   nginx-1.19.3.tar.gz      
fastdfs-nginx-module                            

安装 nginx

openssl-1.1.1h 和 nginx_mod_h264_streaming-2.2.7 对应的是解压目录

[root@fastdfsdht nginx-1.19.3]#./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--with-http_realip_module --with-http_addition_module --with-http_sub_module \
--with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module \
--with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module \
--with-http_stub_status_module --with-http_auth_request_module --with-mail \
--add-module=/usr/local/nginx_mod_h264_streaming-2.2.7 \
--add-module=/usr/local/fastdfs-nginx-module/src \
--with-http_ssl_module \
--with-openssl=/usr/local/openssl-1.1.1h

修改 nginx 目录下的 Makefile 文件

vim /usr/local/nginx-1.19.3/objs/Makefile
去掉第二行中的"-Werror"

修改后如下:
图片.png

修改 nginx_mod_h264_streaming-2.2.7 目录下的 ngx_http_streaming_module.c 文件

[root@fastdfsdht objs]# vim /usr/local/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c

注释掉
 if (r->zero_in_uri)   { 

    return NGX_DECLINED;  

 }

修改后效果如下:
图片.png

[root@fastdfsdht objs]# cd /usr/local/nginx-1.19.3
[root@fastdfsdht nginx-1.19.3]# make && make install

nginx 配置


user  root;
worker_processes  1;

#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 {
	map $http_upgrade $connection_upgrade {
                default upgrade;
                '' close;
        }

    include       mime.types;
    default_type  application/octet-stream;
    client_max_body_size 20M;
    client_body_buffer_size 128k;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

   server {
	listen 80 ssl;
        server_name qiankun.fun; # 你的域名
	    client_max_body_size 50M;
        ssl_certificate  /usr/local/nginx/cert/3678281_qiankun.fun.pem; # 改成你的证书的名字
        ssl_certificate_key /usr/local/nginx/cert/3678281_qiankun.fun.key; # 你的证书的名字
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
	location ~/group[0-9]/ {
           #root   /home/fdfs_storage1;
            ngx_fastdfs_module;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
     }

}

启动 nginx

[root@fastdfsdht conf]# /usr/local/nginx/sbin/nginx

访问

访问地址:
https://qiankun.fun:80/group1/M00/00/0B/wKjcAl9Z2USAfkpPCXW1EEIydL0892.mp4?token=6d3fe0e48771bab6c19c1b048ea2afa7&ts=1603096371
访问效果:
图片.png

建站不啰嗦,上手跟我做(二十一)FastDFS+FastDHT 安装