• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved Location regex does not work in Additional Nginx directives

blueberry

Basic Pleskian
Hi,
I have a problem with additional nginx directives. Some location blocks are ignored by Nginx.
"Location =" does work but location (regex) (when involving a folder) does not work. I have performed some test on my test domain inadoo.com

I have entered the following code in additional nginx directives:
JavaScript:
location = /page321/ {
    deny all; # returns 403 it works. e.g: https://inadoo.com/page321/
}

location /page322/ {
    deny all; # it should return a 403 too but it does not work. It returns a 404 E.g: https://inadoo.com/page322/
}

location ~* .(page\/[0-9]+\/)$ {
    deny all; # https://inadoo.com/page/1/ among other should return a 403 but it does not work
}


1604567700829.png

The following should return a 403 for example according to the last regex directive but it returns a 404.

jojo@DESKTOP-KC3T7B7:~$ curl https://inadoo.com/page/32/ -I
HTTP/2 404
server: nginx
date: Thu, 05 Nov 2020 09:11:37 GMT
content-type: text/html; charset=UTF-8
vary: Accept-Encoding
x-powered-by: PHP/7.4.12
expires: Wed, 11 Jan 1984 05:00:00 GMT
cache-control: no-cache, must-revalidate, max-age=0
link: <https://inadoo.com/wp-json/>; rel="REST API Handbook | WordPress Developer Resources"

Is my formatting wrong?


I also added:
Code:
location ~* /(media|images|cache|tmp|logs)/.*.(php|jsp|pl|py|asp|cgi|sh)$ {
    return 403; # i tested https://inadoo.com/media/bloup.php but it does not return a 403
}
 
Last edited:
I have checked and this one worked on my nginx test server (1.19) but it does not work on PLesk

location ~* "^/page/[\d]+/$" {return 410;}

(to return a 410 for domain.com/page/2/ domain.com/page/23/ domain.com/page/14) ...)
 
I decided to take my pilgrim staff and go up the Plesk mountain.

My first stop was at /etc/nginx/plesk.conf.d/vhosts/inadoo.com.conf (my test domain)

I used location ~* "^/page/[\d]+/$" {return 410;} to see whether it worked.

I haved added the location block with regex at the end of the configuration file and after saving and doing service nginx restart it still didn't work (within server block listening on 80 port)
plesk problem nginx 2.jpg


Then, I have decided to move the directive just below the root directive and it worked.

Then, I have added the location regex just above the location block for index... and boom it worked. So it looks like this location block for index is the culprit.

plesk problem nginx 3.jpg

This file is a Plesk configuration file. Does it mean it is a PLesk bug?

The code added to the Nginx additional settings can be found in vhost_nginx.conf. This code is located after the location block (index) which cause trouble in the system. Would inserting the "include" before the location block indexes would solve the problem?
 
Last edited:
Problem was solved by using the regex in a context like this:

Code:
location / {


    location ~* "^/page/[\d]+/$" {
        return 410;
    }


}

In nginx additional settings
 
If you have unticked "Proxy Mode" to serve files with Nginx, then make sure "Serve static files directly by nginx" is also unticked, then your location block will work. Seems to me if proxy mode is off then the files are served by Nginx anyway.

All the controls for this are a bit cryptic and it should be reworked to make it clearer.
 
location ^~ /exampledirectory {
allow 225.238.108.185;
deny all;
}

Hi above is my ip address but still not allowing me to access the directory.
 
Back
Top