Quantcast
Channel: Nginx Forum - How to...
Viewing all articles
Browse latest Browse all 4759

Basic question about single entry point - why my solution actually *works*?

$
0
0
Hi. I'm a newbie - started playing with nginx in the last days.

I'm trying to make a front controller (single entry point), i.e. . all the requests to non existing files/dirs should be forwarded to index.php, passing "stuff". My host is "http://point1.local" and I want http://point1.local/foo to be forwarded to http://point1.local/index.php (because 'foo' doesn't exist).

I have this right now (and it seems to work): https://paste.ngx.cc/03

That is (shortened):

server {
listen 80 default_server;
server_name point1.local;
index index.php;
root /var/www/html/point/point1;

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

location ~ \.php$ {
try_files $uri =404;

# Bypass the fact that try_files resets $fastcgi_path_info
# see: http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

include fastcgi.conf;

fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}
}

But my question is - I've have read in at least two places, that only ONE 'location' catches, i.e. is "considered". For example here:
http://blog.martinfjordvald.com/2010/07/nginx-primer/ says "The most important things to note (...) and only one location block will ever be run."

Then... how this works? Because it clearly not only does the 'try_files' thing (first location block) , but it *is* also handled then by PHP engine (second location block).

Is it because the first one directs to index.php file and then, in contrast to the information I found, the second location block kicks in?

Viewing all articles
Browse latest Browse all 4759

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>