• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • 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.

Resolved Additional nginx directives outside server scope.

RJBRJB

New Pleskian
Plesk 12.5 Centos 7 nginx php-fpm

Hello, I need to add a map directive to one of my vhosts, specifically the type of block below:

map $http_host $blogid {
default -999;
include /pathto/map.conf ;
}

I need to know where to add this since it needs to be outside the server scope that the Plesk additional directives uses and returns this error when added to my additional directives:

Invalid nginx configuration: nginx: [emerg] "map" directive is not allowed here in /var/www/vhosts/system/xxxxxxxxx.com/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed

Do I need to add some custom files that nginx can include somewhere? Is only the server block editable in Plesk?

Please advise. Thank you.
 
Hi RJBRJB,

such a "map" definition has to be placed in the "http" - section, while an additional directive is part of the "server" section.

You could add it for example directly above the "include" - definition at: /etc/nginx/nginx.conf:

Original:
Code:
...
        include /etc/nginx/conf.d/*.conf;
    }

YOUR example:
Code:
...
        # START RJBRJB personal edits
            map $http_host $blogid {
                default -999;
                include /pathto/map.conf ;
                }
        # End RJBRJB personal edits

        include /etc/nginx/conf.d/*.conf;
    }

( please correct "include /pathto/map.conf", with the FULL PATH, as for example "include /var/www/vhosts/EXAMPLE.COM/httpdocs/.../.../map.conf". The full path will be shown, when you use for example "locate map.conf" over your command line and as well over your wordpress plugin setting site from "Nginx Helper" - section: Nginx map )
 
Thanks UFHH01. This is for the whole server though isn't it? I need to affect only 1 particular vhost. Also the code with the correct path in that file cause nginx error and could not restart.

Please advise. Thank you.

And yes I'm aware of the path, I only shortened it for the example ;)
 
Hi RJBRJB,

yes, http - directives are set globally and can't be set over the Plesk Control Panel ( or over the domain specific settings ). You mentioned an nginx error, but forgot to paste the error. Please be reminded, that we can't guess your errors. It is always a good idea to post depending configuration files, if the error doesn't already points to an issue, so that investigations and possible resolutions are based on your configuration settings.

 
I didn't check the error because I realized I can't have the directive at the global level and removed the code immediately after simply getting a FAILED when trying to restart nginx from the command line.

So is there no way at all to set this directive for an individual domain?
 
Hi RJBRJB,

Please see: https://wordpress.org/plugins/nginx-helper/ :
As you can see, there are really detailed informations and documentations, which you should read, when setting up "map" directives ( and other possible depending settings for "Nginx helper" ).


I didn't check the error because I realized I can't have the directive at the global level and removed the code immediately after simply getting a FAILED when trying to restart nginx from the command line.
Due to the fact, that another try to setup your map - definitions only takes seconds, please consider to do so, so that you can copy your error message for further investigations. We really can't guess what it states.

So is there no way at all to set this directive for an individual domain?
The setup is easy and only takes a few minutes. Just follow the documentation step-by-step, you will see, that it doesn't take much longer, than writing another post on this forum. :p
 
Yes I've read through all of that. Still, nothing there addresses Plesk's limitation in the additional directives section per domain.

I already have everything working for my subdomain multisite install on nginx with nginx caching. I ONLY need to add a map directive for improvement of the static file handling by subsites which can not be placed inside the server block which is what Plesk allows you to modify in the appache & nginx settings section.

As you can see from the instructions there, you are to place a map directive outside the server block

map $http_host $blogid {
default -999;
include /var/www/example.com/htdocs/wp-content/plugins/nginx-helper/map.conf ;
}


server{
## inside server block
#WPMU Files
location ~ ^/files/(.*)$ {
try_files /wp-content/blogs.dir/$blogid/$uri /wp-includes/ms-files.php?file=$1 ;
access_log off; log_not_found off; expires max;
} }


Correct me if I'm wrong but the additional directives section per domain that is the main server block for the vhost correct? And you can not place a map directive in there. If so, again I ask, where can we modify things outside the server block per individual vhost that wont get overwritten, etc. Yes, your solution above would work for the whole server but I need that for an individual vhost.

It would be really nice if you could simply explain Plesk's method of assembly for included conf files for nginx directives per vhost and simply offered the location of or method of creation for a custom file (similar to how it was handled before the UI supported the additional directives when you would manually create customvhost.conf files, etc.) that I could modify outside of the server block instead of kind of rudely telling me to "look here" because that's the plugin you're using. Nothing to do with my plugin, this is a Plesk question concerning nginx directives outside the server block.

You know, if I didn't know any better, I'd think you really didn't want to help me. I'm sure that's not the case.
 
Hi RJBRJB,

as stated before, you have to set "map" directives ONLY outside of the server - block, which is only defined globally at "/etc/nginx/nginx.conf". There is no Plesk integration to add such directives over the Plesk Control Panel at all.

You can as well see in the documentations, that you may define non-automatic map - directives, ( at the moment, the above unique example is for automatic mapping, defined with map.conf - file ) like:
Code:
        map $http_host $blogid {
            default               0;

            example.com           1;
            site1.example.com       2;
            site1.com              2;
        }

You definition ( please see again the unique example ) is ONLY for this specific "map.conf", that you include. You have as well the possibilty to add several more ( as well for other domains ), depending to your include - path, but keep an eye on the used blogids, because they have to be unique.

None of your modifications at "nginx.conf" will be overwritten, in case of updates/updates/patches - new nginx.conf - files will be placed as "nginx.conf.default" or "nginx.conf.default.dpkg-dist", depending to your process you use for updates/upgrades/patches. If you update/upgrade nginx on your very own over apt-get/yum for example, you will be asked, if the new nginx.conf should be replaced with the new default config - file... you see... it's YOUR manual choice, if the file get's replaced or not.


In addition, please be reminded, that modifications of wordpress installations ( this counts as well for plugin - installations ) are never Plesk related, so there might be solutions/resolutions, or work-arounds, which can't be set over the Plesk Control Panel. In this case, please use the recommendation / documentations of the plugin - creator, who should as well offer support for his/her plugin. Odin is not responsible at all for additional software / plugins and it's usage. It was not meant to be rude, when I linked to the recommendations and documentations of the plugin - creator, it was only ( !!! ) to help you, to solve your issue. If you rather would like to read an official statement from an Odin - Team - member, please ignore my posts.
 
Perhaps someone else could benefit from this.

To add additional map directives without throwing an error, create a file in /etc/nginx/plesk.conf.d/ip_default/ with your complete map directives.

Like so:

Code:
/etc/nginx/plesk.conf.d/ip_default/wordpress.conf

map $uri $blogname{
   ~^(?P<blogpath>/[^/]+/)files/(.*)       $blogpath ;
}

map $blogname $blogid{
   default -999;

   #Ref: http://wordpress.org/extend/plugins/nginx-helper/
   #include /var/www/wordpress/wp-content/plugins/nginx-helper/map.conf ;
}

Why does this work?

Because #1, in nginx/plesk EVERY vhost conf is loaded, via includes, into one very long configuration file. Everything you set is global because there is a custom server block for each vhost that specifies its root domain. #2, Plesk includes some hidden config directories that if found can be used to setup your own various configurations, but they're completely empty. These include

/etc/nginx/plesk.conf.d/ip_default/
/etc/nginx/plesk.conf.d/forwarding/
/etc/nginx/plesk.conf.d/wildcards/

Sure, forwarding is disabled in most default firewall configurations but if enabled and limited to a specific scope, the possibilities are endless.

Cheers!
 
Good tip from Paulana, I'm sure it would work - but all of this is no longer neccessary, and has not been for MultiSites created with WordPress 3.5 or later.
German speakers can get the full drop in my exhaustive article on MultiSite and MutliLingual, for others the basic message (copied from wordpress.org) is:

Your first site on a fresh install will put uploaded files in the traditional location of /wp-content/uploads/, however all subsequent sites on your network will be in the /wp-content/uploads/sites/ folder, in their own subfolder based on the site number, designated by the database. These files will be accessible via that URL.
This is a change from Multisite 3.0-3.4.2, where images of subsites were stored in /wp-content/blogs.dir/ and were shown in: http://example.com/files/ and http://example.com/sitename/files and so on. If you started with a Multisite install older than 3.5, it is not an error if your images show with the URL of /files/.


When you REALLY look at what that means, you'll see that there's a path element for subdir websites which is always at the front of the URL; if you remove it you have the real URL of the uploaded files, so no mapping is needed.

I have uploaded a complete nginx config for Plesk Onyx which implements the techniques needed, also for sitemaps and robots.txt - and does not use Apache at all. Enjoy!
 

Attachments

  • nginx-plesk-phpfpm-wordpress-multisite-plesk-onyx.conf.txt
    12.3 KB · Views: 33
Back
Top