Welcome! Log In Create A New Profile

Advanced

404 on try_files

September 21, 2017 12:20PM
I'm going nuts on this. Any help would be much appreciated.

The $request_uri

/h_32/w_36/test.jpg

needs to be routed to

/index.php/img/i/h_32/w_36/test.jpg

index.php will route the request to the "img" controller and "i" method,
then process the image and return it. However, my MVC works off of the
REQUEST_URI. So simply rewriting the url will not work. The REQUEST_URI
needs to modified.

You can see in the last location block that I'm passing in the modified
REQUEST_URI, but Nginx is trying to open /var/www/vhosts/
ezrshop.com/htdocs/h_32/w_36/test.jpg (see **Error Logs** below) and
throwing a 404.

Shouldn't Nginx be trying to send it for processing to index.php?? Why the
404?

In a browser, if I go directly to
https://www.example.com/img/i/h_32/w_36/test.jpg the page comes up just
fine. If I try to go to https://www.example.com/h_32/w_36/test.jpg in my
browser I get 404 and the **Error Logs** you can see below.

root /var/www/vhosts/example.com/htdocs;
index index.php index.html;

set $request_url $request_uri;

location ~ (h|w|fm|trim|fit|pad|border|or|bg)_.*\.(jpg|png)$ {
if ($request_uri !~ "/img/i/") {
set $request_url /index.php/img/i$1.$2;
}

try_files $uri $uri/ /index.php/img/i$1.$2;
}

location / {
try_files $uri $uri/ /index.php$uri?$args;
}

location ~ ^(.+\.php)(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param CI_ENV production; #CI environment constant
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_url;
}

**Error Logs:**

**Log 1:** "/img/i/" does not match "/h_32/w_36/test.jpg", request: "GET
/h_32/w_36/test.jpg HTTP/1.1"

**Log 2:** open() "/var/www/vhosts/ezrshop.com/htdocs/h_32/w_36/test.jpg"
failed (2: No such file or directory), request: "GET /h_32/w_36/test.jpg
HTTP/1.1"
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

404 on try_files

usazelf September 21, 2017 12:20PM

Re: 404 on try_files

Francis Daly October 02, 2017 08:08PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 166
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready