: Non existent image files are not being handled by PHP as they should due to ngnix configuration I am currently building a web application. In order for it to work properly I wrote this rule:
I am currently building a web application. In order for it to work properly I wrote this rule:
location / {
if (!-e $request_filename) {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
rewrite ^(.*)$ /libraries/render.php;
}
}
It is working for URLs with non-existent files like this: test.test/test but not for a non-existent image: test.test/test.png
I have a second rule that might be effecting images:
location ~* .(?:gif|jpe?g|png|ico)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
But I'm not sure how that would prevent the rewrite rule from triggering. It's all the extensions in this rule that are not getting forwarded to render.php
When I remove this rule (by commenting it out) all extensions except .png work. This is very strange.
This is my entire config:
server {
rewrite_log on;
# IPv4
listen 80;
listen 443 ssl;
# IPv6
# listen [::]:80 ipv6only=on;
# listen [::]:443 ssl ipv6only=on;
server_name test.test;
# SSL
ssl_certificate /etc/ssl/private/ssl-bundle.test.test.crt;
ssl_certificate_key /etc/ssl/private/test.test.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/test;
index index.php index.html index.htm;
try_files $uri $uri/ $uri/index.php $uri/index.html $uri/index.htm =404;
disable_symlinks off;
location / {
if (!-e $request_filename) {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
rewrite ^(.*)$ /libraries/render.php;
}
}
location = /config.inc.php {
internal;
}
location /cache/ {
internal;
}
location /libraries/ {
internal;
}
location /images/ {
internal;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
# NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
# With php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
location ~ /.sh {
deny all;
}
location ~* .html$ {
expires -1;
}
location ~* .(?:gif|jpe?g|png|ico)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# Rewrites
rewrite ^(?<filename>.+.(?<type>css|js))$ /compress.php?file=$filename&type=$type;
}
More posts by @YK1175434
1 Comments
Sorted by latest first Latest Oldest Best
So after some trial and error I came up with a working solution that I'm not quite happy with. But at least it works.
Since all "real" images are located in /includes/ or subdirectories I simply rewrote the rule for the images.
So this
location ~* .(?:gif|jpe?g|png|ico)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
Has been turned into this
location ~* ^/includes/.+.(?:gif|jpe?g|png|ico)$ {
expires 168h;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.