nginx conf

if

https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/

http://mogile.web.fc2.com/nginx_wiki/nginx_wiki201510/start/topics/tutorials/config_pitfalls.html

ちなみにNginx公式サイト(Converting Mongrel rules)では以下のようにserverコンテキストを分けて記述することを推奨しています

server {
    listen       80;
    server_name  example.org;
    return       301 http://www.example.org$request_uri;
}
 
server {
    listen       80;
    server_name  www.example.org;
    ...
}

【Nginx】HTTPSへのリダイレクト設定~rewriteではなくreturnでいこう~ | ぴぐろぐ

ディレクトリ構成、ファイル名

nginx - 設定ファイル格納先(Ubuntu)

snippets

https://wiki.debian.org/Nginx/DirectoryStructure

/etc/nginx/snippets: このディレクトリには、Nginx設定の他の場所に含めることができる設定フラグメントが含まれています。潜在的に反復可能な構成セグメントは、スニペットリファクタリングするための良い候補です。
https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-20-04-ja

https://github.com/dallaslu/nginx-templates
nginx-snippets

↑は kebab-case

?nginxのファイル名の命名規則は snake_case or kebab-case

snippets/fastcgi-php.conf

locationの優先順位

個人的には読みやすさを考えて、評価される順(自分が評価してほしいと期待する順)に書いておくのがよいと思います。また、^~ ありの前方一致は混乱を招くため、^/ から始まる正規表現として書いてしまったほうがよいのではないか、と思います
nginx.conf の location の優先順位を正しく理解する - 無印吉澤

try_files

try_filesの引数は最後のみ意味が違う

try_files file ... uri;

file引数はファイルへのアクセス、uri引数は内部リダイレクト
nginxのtry_filesわかりにくすぎ問題 - tsyama記 2019

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

内部リダイレクト → locationディレクティブ再評価 → .php