• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved Additional nginx directives have no effect

theywill

Basic Pleskian
Plesk Onyx
Version 17.8.11 Update #62, last updated on Aug 3, 2019 03:41 AM
CentOS release 6.10
Nginx running as proxy

So I'm sure I'm doing this wrong, but no matter what I place in the nginx directives for a site, nothing works. I can get it to throw errors, which means something is happening, but for instance, when I set autoindex ot on, it doesn't work.

None of these work.

location ~* {
autoindex on;
}

location / {
autoindex on;
}

location /var/www/vhosts/domain.com/httpdocs/123/ {
autoindex on;
}

Anyone know what I'm doing wrong? Thx in advance for the help.
 
If I manually edit the domain's nginx config file @ /etc/nginx/plesk.conf.d/vhosts/domain.com.conf, these changes work. However, if they are included in the Plesk configuration page or manually entered into the file /var/www/vhosts/system/domain.com/conf/vhost_nginx.conf, they do not work. So there's a problem there somehow.

My concern is that the file /etc/nginx/plesk.conf.d/vhosts/domain.com.conf will be overwritten by Plesk.
 
So my concern about the file being overwritten occurred. Putting the directive into the Plesk admin doesn't make a difference though. It just doesn't work.

location ~ ^/mydir/ {
autoindex on;
}

It only works if it's in /etc/nginx/plesk.conf.d/vhosts/domain.com.conf.

How do I get the Plesk admin to work properly? Anyone know?

Thanks for your help.
 
I'd expect the /etc/nginx/plesk.conf.d/vhosts/domain.com.conf to be a symlink to /var/www/vhosts/system/domain.com/conf/nginx.conf.

In /var/www/vhosts/system/domain.com/conf/nginx.conf I'd expect to find the following line twice (for SSL and plain access):
Code:
include "/var/www/vhost/system/domain.com/conf/vhost_nginx.conf";

When you enter the directive in the Plesk GUI, does the /var/www/vhosts/system/domain.com/conf/vhost_nginx.conf file change?
 
@theywill

Your question has become twofold, hence obfuscating the actual root cause of the problem.

One part of your question is related to manual changes, automatic config overrides by Plesk, the symlink method as present in /etc/nginx/plesk.conf.d/ and Plesk Panel itself.

I can assure you that this part is not relevant at all - Plesk Panel works fine, the symlink method is standard and automatic config overrides are normal.

Another part of your question, being the topic that you started with, can be translated to "why the hell does it not work as I expect it to work?".

Well, I had to look many times myself and it occurred to me that your changes in Nginx config are not appropriate at all - they will never work.

First, the part

location /var/www/vhosts/domain.com/httpdocs/123/ {
autoindex on;
}

will never work : you are referring to a location that cannot be found by Nginx - it is not part of the root directory.

Second, the parts

location ~* {
autoindex on;
}

location / {
autoindex on;
}

are too generic - Nginx will never match these patterns : Nginx chooses the best matching pattern, being the default paths as provided by the default Plesk config for Nginx.

In short, a minor tweak of your config should do the trick.

One could try to use an explicit reference to a directory.

For instance, if the full file path is

/var/www/vhosts/domain.com/httpdocs/123/

and the root directory is

/var/www/vhosts/domain.com/httpdocs

and that should be the case by default, then a solution could be using the explicit statement

location /[dir] {
autoindex on;

}

with [dir] replaced by the top-level directory for which you would like to have the autoindex directive create a "file browsing mode" for Nginx.

Please note that the part "location /[dir]" is sufficient - every file or directory in the top-level directory [dir] would be accessible.

Also note that allowing directory browsing access is not very helpful in terms of security - there is some penalty in the form of a less secure domain.

Finally note that directory browsing access is also dependent on the file and ownership structure of all files and directories in the top-level directory [dir].

Anyway, I hope the above helps a bit.

Kind regards.......

PS I am pretty sure that the above solves your issues, but I am not perfectly certain - due to a specific default Nginx config in Plesk, customization of Nginx directives via the Plesk Panel will not always end in the expected result. It is a well-known problem, encountered by many. However, this well-known problem can be solved by creating your own custom Nginx templates - but if not necessary, one should not want customization of Nginx templates.
 
location /[dir] {
autoindex on;

}

--- Yeah. That ^ doesn't work. Not via the Plesk control panel anyway.

location ~ ^/[directory]/ {
autoindex on;
}

That's ^ what I'm actually using, but I have to edit the domain conf file that gets overwritten. I've created a routine to recopy my changes into it to solve the problem temporarily.

When I make changes via Plesk, you do see the changes reflected in the include. They just appear to have no affect. I'm sure it's my fault and the proper syntax of the directory. Hence my questions.

Thanks for the replies though. Unfortunately, I'm in a period where I cannot continue testing. However, if you have other ideas, I'll try them later this month.

Best regards.
 
@theywill

You should not use the ^ in the declarations - not in your case.

In addition, it might be a typo, but there is a huge difference between

~ ^/[dir] (read: will not work)

and

~^ /[dir] (read: can work, but should not be used in this case).

and if it is not a typo, it still has to be stated that you should not use something like ~ or ^ in your declarations, at least not for the intended purpose.

Kind regards..........
 
Back
Top