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 domain.com/logo_path/cat.png
.
Should I use routes.php
or Nginx configuration
to solve this ?
Basically, I want to map all images from /app/files/logo_path/*
to domain.com/logo_path/*
2
Answers
With nginx, you can do it with the following configuration:
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 analias
directive instead. Here is an excerpt from the nginx documentation: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!