无法访问位于nginx站点文档根目录之外的PHP文件


Unable to access PHP files sitting outside the document root of an nginx site

我有一个基于CodeIgniter构建的PHP应用程序。我有一个很大比例的网站(系统文件夹的人谁知道CodeIgniter)坐在文档根下。

下面是Nginx配置文件

server {
server_name www.domain.local;
root /var/www/html/domain/frontend;
include /etc/nginx/conf.d/ci_vhost;
}

这是我试图访问/var/www/html/ci/2.0.2/system时遇到问题的文件夹

使用Apache,我从来没有遇到过访问文档根目录下的php文件的问题。

有谁知道为什么我遇到这个问题与Nginx?

谢谢。

您可以访问服务器上的任何文件夹,只需使用"alias"或"root"指令相应地配置nginx,这两个指令都可以在特定块中多次定义。

server {
    # Default root
    root /var/www/html/domain/frontend;
    location /abc
        # Uses default root
        ...
    }
    location /xyz
        # defines it's own root
        root /var/www/some/folder;
        ...
    }
    location /123
        # aliases to another folder
        alias /etc/some/folder;
        ...
    }
    location /
        # Uses default root
        ...
    }   
}

阅读别名和根的区别

对于php,您将不得不考虑open_basedir限制。