Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

nginx

I have a PHP application built on CodeIgniter. I have a large proportion of the website (the system folder to anyone who knows CodeIgniter) sitting below the Document Root.

Here is the Nginx conf for the website

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

Here is the the folder I am having issues trying to access /var/www/html/ci/2.0.2/system

With Apache, I never had issues accessing php files below the document root.

Does anyone know why i am experiencing this issue with Nginx?

Thanks.

like image 787
Ben McRae Avatar asked Dec 01 '11 22:12

Ben McRae


People also ask

What is Nginx document root?

The root directive specifies the root directory that will be used to search for a file. To obtain the path of a requested file, NGINX appends the request URI to the path specified by the root directive.

What does try_files do in nginx?

Using try_files means that you can test a sequence. If $uri doesn't exist, try $uri/ , if that doesn't exist try a fallback location.


1 Answers

You can access any folder on your server and just have to configure nginx accordingly using either the "alias" or "root" directives both of which can be defined multiple times within specific blocks.

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
        ...
    }   

}

Read up on the difference between alias and root

For php, you will have to consider open_basedir restrictions.

like image 51
Dayo Avatar answered Sep 19 '22 21:09

Dayo