Today I Learned - Rocky Kev

TIL how NGINX knows to look for index.html vs index.php

POSTED ON:

TAGS:

What happens when visitor hits /foo/bar URL?

  1. NGINX looks at the longest prefix-based location, which is / and chooses it for current request

    • It also checks for any regex locations but finds none that match to the URI
  2. So it attempts to actually see if there is root directive's value + /foo/bar file on its system. That is, it checks using a stat system call, whether /var/www/html/foo/bar exists. If the file indeed exists, it will just serve it
    If the file does not exist, then NGINX attempts to see if /var/www/html/foo/bar/ directory exists. It it does, then NGINX will check the existence of files defined by index directive (e.g. index.html) in a defined order, and use those to satisfy requests (if they do exist), e.g. /var/www/html/foo/bar/index.html

  3. If those do not exist, NGINX finally knows it needs to serve using /index.php. How the try_files works is that "reaching" its last argument will result in another location search, and this time it will match the regex location of \.php$.

https://stackoverflow.com/a/57548387/4096078


Related TILs

Tagged:

TIL how NGINX knows to look for index.html vs index.php

What happens when visitor hits /foo/bar URL?

TIL php-fpm

PHP runs as a separated service when using PHP-FPM. By using this PHP version as language interpreter, requests are processed through a TCP/IP socket; so that the Nginx web server only handles the HTTP requests and PHP-FPM interprets the PHP code. The fact of having two separate services is key for increasing efficiency.

TIL of what happens when you put a random url in your DNS records

So when you use a 'A' record, it points to the IP address. If you put a site you don't own, and it gets redirects, it'll 404 because the header metadata!