nginx增加rtmp流媒体模块
#查看编译模块
[root@wow wwwroot]# nginx -V
nginx version: nginx/1.12.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2l 25 May 2017
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-openssl=/root/lnmp1.4/src/openssl-1.0.2l --with-ld-opt='-ljemalloc'
#关闭nginx服务,重新编译
[root@wow wwwroot]# service nginx stop
Stoping nginx... done
[root@wow wwwroot]# service php-fpm stop
Gracefully shutting down php-fpm . done
[root@wow wwwroot]# ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --with-openssl=/root/lnmp1.4/src/openssl-1.0.2l --with-ld-opt='-ljemalloc' --add-module=/root/nginx-rtmp-module-master
#配置nginx
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
application hls { #rtmp推流请求路径
live on;
record off;
}
}
}
server {
listen 80;
server_name localhost;
location /stat { #第二处添加的location字段。
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl { #第二处添加的location字段。
root /usr/local/nginx/nginx-rtmp-module/;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
防止图片盗链
location /images/ {
valid_referers none blocked http://www.example.com example.com;
if ($invalid_referer) {
return 403;
}
}
重定向并显示指定图片
valid_referers blocked http://www.example.com example.com;
if ($invalid_referer) {
rewrite ^/images/uploads.*\.(gif|jpg|jpeg|png)$ http://www.examples.com/banned.jpg last
}
如何拒绝一些User-Agents?
你可以很容易地阻止User-Agents,如扫描器,机器人以及滥用你服务器的垃圾邮件发送者。
if ($http_user_agent ~* LWP::Simple|BBBike|wget) {return 403;}
if ($http_user_agent ~* Sosospider|YodaoBot) {return 403;}
只允许我们的域名的访问
如果机器人只是随机扫描服务器的所有域名,那拒绝这个请求。你必须允许配置的虚拟域或反向代理请求。你不必使用IP地址来拒绝。
if ($host !~ ^(test.in|www.test.in|images.test.in)$ ) {return 403;}
限制Nginx连接传出
黑客会使用工具如wget下载你服务器本地的文件。使用Iptables从nginx用户来阻止传出连接。ipt_owner模块试图匹配本地产生的数据包的创建者。下面的例子中只允许user用户在外面使用80连接。
/sbin/iptables -A OUTPUT -o eth0 -m owner –uid-owner vivek -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT