【问题标题】:nginx, why download on param query said me an errornginx,为什么在参数查询上下载说我一个错误
【发布时间】:2021-08-05 20:05:49
【问题描述】:

这是我的问题。我已将此代码添加到我的 nginx.conf 中:

 location ~/.mp4 {
         if ($args_dl = "1") {
                types { application/octet-stream (.mp4); }
                default_type application/octet-stream;
         }
 }

当我重新启动 nginx 时它说我

nginx: [emerg] "types" 指令在 /etc/nginx/nginx.conf:26 中是不允许的

为什么?第 26 行是types { application/octet-stream (.mp4); }

谢谢

编辑:真正的问题是:为什么如果我添加到代码if ($args_dl = "1") { nginx 说我“类型”的错误?我不明白它是如何工作的

RIEDIT:我认为这是因为我在 if 中输入了类型,但它不适合。如果没有 if,我怎么能做同样的事情?

RIRIEDIT:

我试过这个:

    location ~* ^/.+\.(?:gif|jpe?g|png|mp4)$ {
    autoindex off;
    if ($arg_dl = "1") {
        rewrite ^(.*)$ /download$1 last;
    }
}
location ~ /download/.+\.(mp4) {
    internal;
    alias /home/$1;
    types {}
    expires -1;
    default_type application/octet-stream;
}

它不起作用,因为我不知道如何设置别名以动态获取视频的 url 并使用我拥有的所有不同视频,当我更改 url 时浏览器给我 500 内部服务器错误位置链接

【问题讨论】:

    标签: nginx


    【解决方案1】:

    来自docs

    语法:类型 { ... }

    上下文:http、服务器、位置

    如您所见,在允许的上下文中没有if。换句话说,您可以将types 放在httpserverlocation 块中,但不能放在if 块中。

    【讨论】:

    • 我该如何解决?我需要那个功能
    • @FounderOnepiecepower 没有解决办法。但是,您可以从 $args_dl 转到不同的方法,即您可以使事物对 location ~ /play/.+\.mp4$location ~ /download/.+\.mp4$ 做出不同的响应。
    • 我试过这个stackoverflow.com/questions/54745612/… 但对我不起作用。我不知道如何根据我给他的链接动态设置别名。我更新了问题
    • @FounderOnepiecepower 您可以创建多个下载位置来克服别名问题。例如。 location ~ /download/.+\.(jpg|png|jpeg) 用于图像,location ~ /download/.+\.(mp4) 用于视频。这样您就可以为每个人定义不同的alias
    • 问题是我有几个视频。我尝试了 alias /home/$1 但它仍然返回 404。我该怎么做?看看我在帖子开头更新的代码
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多