1+ #
2+ # Selection order:
3+ # * location = # exact
4+ # * location ^~ # longest prefix (priority)
5+ # * location ~ or ~* # first regex match (~* is case-insensitive)
6+ # * location / # longest prefix (fallback)
7+ #
8+ # Ref https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms#how-nginx-chooses-which-location-to-use-to-handle-requests
19server {
210 listen 443 ssl;
311 listen [::]:443 ssl;
@@ -16,28 +24,45 @@ server {
1624 log_not_found off;
1725 server_tokens off;
1826
19- # Prevent hidden "dotfiles" from being served
20- location ~ /\. {
27+ location = /favicon.ico {
2128 access_log off;
22- deny all;
29+ try_files /wp-content/themes/<%= @active_theme %> /i/favicon.ico /wp-content/themes/jquery/i/favicon.ico;
30+ }
31+
32+ location = /robots.txt {
33+ access_log off;
34+ try_files $uri /wp-content/themes/<%= @active_theme %> /robots.txt;
2335 }
2436
2537 # Avoid noise in PHP error logs from bots accessing includes
2638 #
27- # > Uncaught Error: Call to undefined function __()
39+ # > Error: Call to undefined function
2840 # > in /srv/wordpress/sites/jquery_com/wp-admin/includes/file.php
2941 #
3042 # https://core.trac.wordpress.org/ticket/9185
31- location ^~ /wp-includes/(.*).php {
43+ location ^~ /wp-admin/ includes/ {
3244 access_log off;
3345 deny all;
3446 }
35- location ^~ /wp-admin/includes/ {
47+
48+ include /etc/nginx/wordpress-subsites/<%= @host %> .d/*.conf;
49+
50+ # Prevent hidden "dotfiles" from being served
51+ location ~ /\. {
3652 access_log off;
3753 deny all;
3854 }
3955
40- include /etc/nginx/wordpress-subsites/<%= @host %> .d/*.conf;
56+ # Avoid noise in PHP error logs from bots accessing includes
57+ #
58+ # > Error: Call to undefined function
59+ # > in /srv/wordpress/sites/jquerymobile/wp-includes/customize/class-wp-customize-cropped-image-control.php
60+ #
61+ # NOTE: Must not deny /wp-includes/ by prefix because WordPress serves JS/CSS from here.
62+ location ~ /wp-includes/(.*).php {
63+ access_log off;
64+ deny all;
65+ }
4166
4267<%- if @gilded_wordpress -%>
4368 # Avoid matching /resources/ itself as that can be a real page
@@ -47,29 +72,19 @@ server {
4772 }
4873<%- end -%>
4974
50- location = /favicon.ico {
51- access_log off;
52- try_files /wp-content/themes/<%= @active_theme %> /i/favicon.ico /wp-content/themes/jquery/i/favicon.ico;
53- }
54-
55- location = /robots.txt {
56- access_log off;
57- try_files $uri /wp-content/themes/<%= @active_theme %> /robots.txt;
58- }
59-
6075 location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
6176 expires 24h;
6277 }
6378
64- location / {
65- try_files $uri $uri/ /index.php$is_args$args;
66- }
67-
6879 location ~ \.php$ {
6980 client_max_body_size 25M;
7081 try_files $uri =404;
7182 fastcgi_pass unix:/run/php/php<%= @php_fpm_version %> -fpm.sock;
7283 fastcgi_param SCRIPT_FILENAME $request_filename;
7384 include /etc/nginx/fastcgi_params;
7485 }
86+
87+ location / {
88+ try_files $uri $uri/ /index.php$is_args$args;
89+ }
7590}
0 commit comments