I have the following configuration for my wp site which is running on nginx 1.8.1
location ^~ /wp-login.php {
allow 10.0.0.0/24;
deny all;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
When I opening http://example.com/wp-login.php from my LAN, it downloads php file instead of passing it to fastcgi. After that I added all fastcgi lines inside of wp-login.php location and it began to work.
location ^~ /wp-login.php {
allow 10.0.0.0/24;
deny all;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
But is that the only way? Can I make a ordering of passing specific pattern on nginx?
Thanks beforehand.
Once nginx has selected a location block to serve a request, it generally stays within that location block. Only if there's some kind of internal redirect - i.e. you do a
rewrite
on the URI,try_files
orindex
orerror_page
- then the request will be re-evaluated and a different location might end up serving the request.Rather than trying to write your configuration to pass a request through multiple location blocks, you should instead consider using
include
and configuration snippets kept in other files so that configuration shared between multiple locations can be kept in a single file - it's simpler, is the same effort saving when it comes to duplicated configuration and it performs better than redirecting.