【问题标题】:Nginx Forbideen 403Nginx 禁止 403
【发布时间】:2019-06-07 16:20:00
【问题描述】:

我通过 Nginx 服务器运行流媒体服务,

我只想通过 1 个域运行流(格式 m3u8)

    server {
        listen 80;
    server_name www.mydomain.com;
     if ($host != "www.mydomain.com") {

            return 403;
        }
}

在这里,当我测试链接时,例如:http://ip_server_stream/live/1.playlist.m3u8 在浏览器上它会在所有域上给出 Forbideen 403 错误

如果我只放了

server {
            listen 80;
        server_name www.mydomain.com;
}

它适用于所有域和 VLC

我只想要链接 http://ip_server_stream/live/1.playlist.m3u8 在 www.mydomain.com 上工作,而不是在其他域或 vlc 上工作

我的 nginx 版本是 1.7.5

这是我的 nginx 配置文件

这是我的配置文件,即使我有 IF 条件,它也会在所有域上给出错误 403

worker_processes  8;
        error_log  logs/error.log debug;
        events {
        worker_connections  1024;
        }
        rtmp {
        server {
        listen 1991;
        allow play all;

        application live {
        allow play all;
        live on;
        hls on;
        hls_nested on;
        hls_path /HLS/live;

        }


        }
        }


        http {
        include       mime.types;
        default_type  application/octet-stream;


        server {
            listen 80;
        if ($http_host != "www.mydomain.com") {

                    return 403;
                }


        location /live {

        index  index.html index.htm;


        types {
        application/vnd.apple.mpegurl m3u8;
        }
        alias /HLS/live;
        add_header Cache-Control no-cache;
        }



        location / {

        root   html;
        index  index.html index.htm;
        }   
        }


        }

【问题讨论】:

    标签: nginx nginx-config


    【解决方案1】:

    试试这个。

    if ($http_host != "www.mydomain.com") {
        return 403;
    }
    

    【讨论】:

    • 有没有办法禁止用户通过 VLC 使用链接?使用 cors 我可以禁用其他网站来使用它,但 VLC 或在移动设备上它仍然可以工作
    • 对不起...我不熟悉 VLC。我只能提供关于 nginx 的帮助。请看另一个答案。
    【解决方案2】:

    让我们做两台服务器。其中一个是虚拟的,只返回 403 响应。

    http {
    
        # dummy server.
        server {
            listen 80 default_server;
    
            location / {
                return 403;
            }
        }
    
        # main server.
        server {
          listen 80;
          server_name www.mydomain.com;
    
          # PLEASE WRITE YOUR CONFIGURATION.
        }
    }
    

    【讨论】:

    • 和以前一样的问题,如果有问题,你能检查我的congif代码吗?
    • 真的吗?请检查响应状态码是否正确,例如将返回码从 403 更改为 503。我怀疑您重新加载配置失败。
    猜你喜欢
    • 2019-04-17
    • 2019-05-29
    • 1970-01-01
    • 2019-01-28
    • 2016-04-24
    • 2019-01-23
    • 2015-02-02
    • 2021-10-26
    相关资源
    最近更新 更多