【问题标题】:nginx redirects all files with or without extensions except a fewnginx 重定向所有有或没有扩展名的文件,除了少数
【发布时间】:2021-10-05 10:18:09
【问题描述】:

如何匹配所有带或不带扩展名的文件,除了扩展名为txt、pdf、jpeg的文件。

在我的 Nginx 配置中,它会毫无限制地下载所有文件。

location ~ .+(?<!\.pdf|\.txt|\.jpeg)$ {
        
    auth_request /auth.php;
    error_page 401 = @login;
} 

谢谢

【问题讨论】:

    标签: nginx mod-rewrite


    【解决方案1】:

    解决了我没有将 auth.php 作为异常包含在内,这会导致循环。

    location ~ .+(?<!/|auth.php|.txt|.pdf|.jpeg|.jpg|.png)$ { 
    
        auth_request /auth.php;
        error_page 401 = @login;
    
    }
    

    【讨论】:

      【解决方案2】:

      定义两个位置怎么样?例如

      location ~ \.(pdf|txt|jpeg)$ {
          # handle those with the extension pdf, txt, jpeg
      }
      location / {
          # handle all files with or without extension
      }
      

      【讨论】:

      • 它对我不起作用,感谢您的帮助。
      猜你喜欢
      • 2023-03-14
      • 1970-01-01
      • 2014-12-17
      • 2012-03-04
      • 2014-03-15
      • 1970-01-01
      • 1970-01-01
      • 2015-01-31
      • 1970-01-01
      相关资源
      最近更新 更多