How to expose a specific directory that is not in public/ – in Laravel?

I’m on a really old Laravel 4.2 project. I stored all files in /app/files/ for security reasons. I would like to make one of my directories to public access, this one /app/files/logo_path/.

Let’s say … I have a file cat.png located at

Ex. /app/files/logo_path/cat.png

I want my domain to return it like this

Should I use routes.php or Nginx configuration to solve this ?

Basically, I want to map all images from /app/files/logo_path/* to*


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

With nginx, you can do it with the following configuration:

location ^~ /logo_path/ {
    root /app/files; # you should specify full path to /app/files folder here!

I assume you haven’t had any other files than images in /app/files/logo_path/, that’s why I use ^~ location modifier to prevent any attempt to request any PHP script from this path (if such a request would come, it won’t be intercepted with PHP handler location and interpreted with the PHP-FPM engine).

This configuration isn’t a security flaw, because this location block would be used only for requests starting with /logo_path/ prefix. If you want to use different prefix, root directive won’t be suitable for you, for that case you would need to use an alias directive instead. Here is an excerpt from the nginx documentation:

For example, with the following configuration

location /i/ {
    root /data/w3;

The /data/w3/i/top.gif file will be sent in response to the /i/top.gif request.

A path to the file is constructed by merely adding a URI to the value of the root directive. If a URI has to be modified, the alias directive should be used.

Method 2

nginx configuration is the way to solve this problem. There is nothing much to be gained by passing these static image objects through php unless you want to show them only to authorized site visitors.

nginx is faster than php for delivering static objects. It mmaps the objects’ files to RAM and then sends them to browsers. Fast!

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x