• We value your experience with Plesk during 2024
    Plesk strives to perform even better in 2025. To help us improve further, please answer a few questions about your experience with Plesk Obsidian 2024.
    Please take this short survey:

    https://pt-research.typeform.com/to/AmZvSXkx
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Issue nginx directives not working?

Azurel

Silver Pleskian
Hey,

for subdomain cdn.example.com

I have set on
- Proxy mode
- Smart static files processing
- Serve static files directly by nginx

in "Additional nginx directives" I put "deny all;" and all image requests get a 403 from nginx. Now I want block requests for a single folder
Code:
location ~* ^/images/ {
deny all;
}
but all request like with cdn.example.com/images/picture.png get status code 200. I have access to the images. What is here my big mistake?


OR


I set off
- Smart static files processing
- Serve static files directly by nginx

and in "Additional Apache directives"
Code:
<Directory /var/www/vhosts/example.com/httpdocs>
    Order allow,deny
    Deny from all
</Directory>
but all request like with cdn.example.com/images/picture.png get status code 200. Only php access cdn.example.com get a error page. Why is here still nginx processing the static files?!
 
Last edited:
I have a similar issue, in additional nginx directives the following does not work:


Code:
location ~ ^/page/[0-9]+/?$ {
    return 404;
}

It is like nginx does not "see" the location blocks.
 
Hey,
I set off
- Smart static files processing
- Serve static files directly by nginx
...
but all request like with cdn.example.com/images/picture.png get status code 200. Only php access cdn.example.com get a error page. Why is here still nginx processing the static files?!
"Off" does not mean that Nginx is turned off. Nginx is always on. "Off" means that "proxy mode" is turned off, so only Nginx is processing requests. Your .htaccess is never used, because Apache does not get any requests from Nginx any longer.
 
@blueberry
The solution here is that you must disable nginx settings for
- Serve static files directly by nginx
- Enable nginx caching

and put this code in Additional nginx directives
Code:
location ~* ^/(.*\.(css|js|jpeg|jpg|png|gif|webp|......ADD_ALL_FILE_TYPES_YOU_NEED.......))$ {
    try_files $uri @fallback;

    expires 30d;
    add_header Cache-Control "public";

    location ~ ^/page/[0-9]+/?$ {
        return 404;
    }
}

nginx working nested. What comes first is processed first and everything after that is ignored.
When you enable static files by nginx, nginx have in /etc/nginx/plesk.conf.d/vhosts already this line in conf-file.
Code:
    location ~ ^/(.*\.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|eot|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|svg|swf|tar|tgz|ttf|txt|wav|woff|woff2|xls|xlsx|zip))$ {
        try_files $uri @fallback;
    }
So your "location" will be ignored. Solution is to disable static files in nginx and put this line in your textbox and add your location in it, not afterwards.
Maybe someone can explain it better. ;)
 
@blueberry
The solution here is that you must disable nginx settings for
- Serve static files directly by nginx
- Enable nginx caching

and put this code in Additional nginx directives
Code:
location ~* ^/(.*\.(css|js|jpeg|jpg|png|gif|webp|......ADD_ALL_FILE_TYPES_YOU_NEED.......))$ {
    try_files $uri @fallback;

    expires 30d;
    add_header Cache-Control "public";

    location ~ ^/page/[0-9]+/?$ {
        return 404;
    }
}

nginx working nested. What comes first is processed first and everything after that is ignored.
When you enable static files by nginx, nginx have in /etc/nginx/plesk.conf.d/vhosts already this line in conf-file.
Code:
    location ~ ^/(.*\.(ac3|avi|bmp|bz2|css|cue|dat|doc|docx|dts|eot|exe|flv|gif|gz|htm|html|ico|img|iso|jpeg|jpg|js|mkv|mp3|mp4|mpeg|mpg|ogg|pdf|png|ppt|pptx|qt|rar|rm|svg|swf|tar|tgz|ttf|txt|wav|woff|woff2|xls|xlsx|zip))$ {
        try_files $uri @fallback;
    }
So your "location" will be ignored. Solution is to disable static files in nginx and put this line in your textbox and add your location in it, not afterwards.
Maybe someone can explain it better. ;)


Thank you so much , it was not exactly what I needed but it helped me a lot to find the solution.

In fact I wanted to block wordpress pages like /page/124443/ /page/22334/
So, I didn't want to block a filename or an extension in particular.

Consequently, here is the solution that worked for my wordpress installation. ===>



Code:
location / {

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

    location ~* "^/([a-z0-9\-]+)\/[a-zA-Z0-9]+$" {
        return 301 https://mydomain.com/$1/ ;

    }

    if (!-e $request_filename) {
        rewrite ^/(.+)$ /index.php last;
    }

}
 
Last edited:
This first line
Code:
location ~* ^/(.*\.(css|js|jpeg|jpg|png|gif|webp............
blocks nothing. This line check its a real file
Code:
try_files $uri @fallback;
for catch this files for set caching.
 
This first line
Code:
location ~* ^/(.*\.(css|js|jpeg|jpg|png|gif|webp............
blocks nothing. This line check its a real file
Code:
try_files $uri @fallback;
for catch this files for set caching.
Thank you, i get it now. I have tried the try_files without any luck in the past. This explains everything.
 
Back
Top