【问题标题】:Nginx: How to access files outside of root using PHP?Nginx:如何使用 PHP 访问根目录之外的文件?
【发布时间】:2019-09-08 02:45:11
【问题描述】:

最初,我的根 /var/www/html 文件夹中有一堆文件夹,这些文件夹受 location 块保护,如下所示:

location ~ /(folder1|folder2|folder3) {
  internal;
}

但现在我意识到,如果我将它们完全从我的根文件夹中取出会更有意义。不过,我希望能够通过 PHP 文件发送这些文件,我正在做这样的事情:

$file_path = '/' . $path . '/' . $prefix . '.' . $suffix;
header('X-Accel-Redirect: ' . $file_path);
header("Content-Type: text/plain");

但是,如果我将这些文件夹放在 /var/www/html 之外并将它们放在 /var/www/protected 中,我如何在 PHP 中访问这些文件?

【问题讨论】:

    标签: php nginx nginx-config


    【解决方案1】:

    您可以在位置标签内使用root ... 来区分它... 您可以在此处使用auth_request 获取更多选项auth_request nginx

    【讨论】:

      猜你喜欢
      • 2021-05-12
      • 1970-01-01
      • 2016-10-17
      • 2017-01-24
      • 1970-01-01
      • 2015-02-21
      • 2016-04-30
      • 2013-07-27
      • 2019-10-22
      相关资源
      最近更新 更多