Hi there,
I'm new to Nginx and I'm trying to add a location directive to my config file with a regular expression and it just won't work.
I have a block that works to restrict my Wordpress URLs and a couple of other files:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|wp-login\.php$) {
allow <my ip here>;
deny all;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
default_type text/html;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
What I am trying to do is restrict access to another page at this URI:
/access/report.html
I want to just add it to the above location block that is already working, but I can't seem to get the syntax correct on this line:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|wp-login\.php$) {
I've tried things like:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|report\.html|wp-login\.php$) {
and many others...
Nothing works. I get an "Access denied." message in the browser when I try accessing it (the others still restrict everything fine, wp-admin, etc). Both from the IP I'm restricting and outside of it.
Note I DO have another PHP location block below this, not sure if it is interfering:
location ~ \.(php)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
default_type text/html;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Also, could it be because it is a .html file as opposed to a .php file extension for some reason (in the regex, or due to other matching location directives?)
Thanks!
I'm new to Nginx and I'm trying to add a location directive to my config file with a regular expression and it just won't work.
I have a block that works to restrict my Wordpress URLs and a couple of other files:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|wp-login\.php$) {
allow <my ip here>;
deny all;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
default_type text/html;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
What I am trying to do is restrict access to another page at this URI:
/access/report.html
I want to just add it to the above location block that is already working, but I can't seem to get the syntax correct on this line:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|wp-login\.php$) {
I've tried things like:
location ~ ^/(wp-admin|opcache-cp\.php|apcu\.php|report\.html|wp-login\.php$) {
and many others...
Nothing works. I get an "Access denied." message in the browser when I try accessing it (the others still restrict everything fine, wp-admin, etc). Both from the IP I'm restricting and outside of it.
Note I DO have another PHP location block below this, not sure if it is interfering:
location ~ \.(php)$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
default_type text/html;
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
Also, could it be because it is a .html file as opposed to a .php file extension for some reason (in the regex, or due to other matching location directives?)
Thanks!