Welcome! Log In Create A New Profile

Advanced

help with location directive

Posted by SH10151 
help with location directive
August 03, 2016 07:35PM
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!
Re: help with location directive
August 06, 2016 03:02AM
shameless bump
Re: help with location directive
August 06, 2016 01:54PM
You'd think with Nginx stating there are lots of bad configuration tutorials out there (which I've already been bitten by), they would be more active in these forums in an effort to set the record straight. Most posts in this forum have no replies, including this one. Lots of people seeking help here and very few actual replies, and certainly not by many actual Nginx people...
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 254
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready