• 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

Question custom nginx config

andyxyz

Basic Pleskian
Server operating system version
buntu 2204
Plesk version and microupdate number
obsidian
HI all
I want to add a new server block to nginx.conf
The easiest way seems to be a simple

if exists ...
include "/var/www/vhosts/system/domain.com/conf/vhost_nginx.conf";

at the bottom

However, I cant find the right file to add this to. /usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php inserts the line at the end of search server{} block

Where can I inject this?
 
May I ask what the overall end goal? Is it something that should be affecting all sites? Because the way plesk works is that if you edit the main config when there's any changes made the site's configuration file will be overwritten. If you're trying to edit the template so it affects all sites then you'll want to copy the template you want to edit from /usr/local/psa/admin/conf/templates/default to /usr/local/psa/admin/conf/templates/custom and edit accordingly to your liking. You can learn more by reading up on Changing Virtual Hosts Settings Using Configuration Templates
 
/usr/local/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php is the correct file to add such an include, you just need to place it at the proper position.
We use the very same mechanics to include a custom file that blocks "bad" bots and access to some files and directories globally. (like xmlrpc.php or .env/.git)

the only downside to this is that you have (or should at least) to redo that on every Plesk update...
 
Hi there

All attempts to edit nginxDomainVirtualHost.php insert includes INTO the server blocks.. each block

we want an include at the bottom of this file

Not matter where I put the include it is the wrong location.

in essence all I want is
if custom.conf exists include custom.conf (which will contain a custom server block)
 
How hard can this be?
Can anyone point me to the file that needs editing to add something to the very bottom of the nginx.conf file?
 
If you add something to be bottom of the nginxDomainVirtualHost.php, it will get added after the server{} block for https/ssl vhosts and inside the server{} block for the port 80 vhosts.
Do not ask my why, but the whole templating stuff of Plesk is quite complex and sometimes beyond my understanding...

But if you add something like this to the end of nginxDomainVirtualHost.php, you should get exactly what you want - the only caveat is that you need to have SSL enabled for the website, in order to make it work. (but should be default anyway)
Code:
<?php if (!$OPT['ipAddress']->isIpV6()): ?>
  <?php if ($OPT['ssl']): ?>
    include /etc/nginx/my-custom[.]conf;
  <?php endif ?>
<?php endif ?>

the isIpV6 if() statement is here, so Plesk does only not add the custom config twice (on servers with an IPv4 AND IPv6 address, where it adds a virtualhost for both IP addresses)
 
Back
Top