Answer the question
In order to leave comments, you need to log in
How to check if a file exists in NGINX and return it if it exists?
The architecture of the application is such that when a conditional request for a picture
/uploads/cache/100x100/bla-bla.jpg
executes a php script, and if the file does not exist, then it "resizes" it to the desired size and puts it in the appropriate folder
. Now the attendance has increased and I would like to use Nginx check if there is a file and if there is, then immediately give it without requests to php-fcgi
Google found me this example:
location ^~ /uploads/cache/{
if (-f $request_filename) {
break;
}
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_index index.php;
fastcgi_param SCRIPT_NAME /resize.php;
fastcgi_param DOCUMENT_URI /resize.php;
fastcgi_param SCRIPT_FILENAME /home/site/www/resize.php;
fastcgi_param HTTPS off;
fastcgi_pass php5;
}
Answer the question
In order to leave comments, you need to log in
Nginx has long had a trifile for this,
something like this
location / {
gzip on;
index index.php; ## Allow a static html file to be shown first
try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
}
location @handler { ## Magento uses a common front handler
rewrite / /index.php;
}
location ~ .php$ { ## Execute PHP scripts
if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
expires off; ## Do not cache dynamic content
fastcgi_pass 127.0.0.1:9000;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 3000s;
fastcgi_read_timeout 3000s;
fastcgi_send_timeout 3000s;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
fastcgi_param MAGE_RUN_TYPE store;
include fastcgi_params; ## See /etc/nginx/fastcgi_params
}
Not the best example, but I think that's enough to understand
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question