'How to hide my php includes directory with nginx but still be able to include files from it?

My php files are stored in following folders:

src
--hiddenstuff
---lotsofsubdirs
--public
---lotsofsubdirs

in "hiddenstuff" i place all the php libraries which i include from the php files which are in the "public" directory.

What i am trying to do is to hide "hiddenstuff" directory somehow from public and still be able to include files with php include() from this directory and all the subdirs.

My current docker setup is this:

services:
  nginx:
    container_name: nginx
    build: ./docker/nginx
    command: nginx -g "daemon off;"
    links:
      - php
    ports:
      - "80:80"
    volumes:
      - ./src/public:/var/www/html
  php:
    container_name: php
    build: ./docker/php
    links:
      - mysql
    ports:
      - "9000:9000"
    volumes:
      - ./src/public:/var/www/html
    working_dir: /var/www/html

nginx.conf

server {
    listen 80;
    index index.php index.htm index.html;

    root /var/www/html;

    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;


    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }


}

Problem I face is that when i try to include files from "hiddenstuff" directory in php - it says that i can't access them. So how to solve this? Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source