Applicable to:
- Plesk for Linux
Question
How to add additional nginx directives globally, so that these directives will not be overwritten after updates?
Answer
-
Connect to a Plesk server via SSH.
-
Create the directives.conf file inside the
/etc/nginx/conf.d/
directory:# touch /etc/nginx/conf.d/directives.conf
-
Now, open the created
/etc/nginx/conf.d/directives.conf
file in a text editor. In this example, we use the vi editor:# vi /etc/nginx/conf.d/directives.conf
-
Add required directives. For example:
# cat /etc/nginx/conf.d/directives.conf
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;
proxy_buffers 8 16k;
proxy_buffer_size 32k;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k; -
Save the changes and close the file.
-
Make sure that the new directives do not break nginx configuration:
# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful -
Reload nginx configuration to apply the changes:
# service nginx reload
Comments
9 comments
Hi
I have tried this but with no luck
I want to do a server rule which redirects the public IP address to the domain (not using .htaccess) so ...
curl -I http://<IP Address>
and
curl -I https://<IP Address>
goes 301 to https://www.domain.com
I tried putting the server rule below in the additional nginx directives but this is not allowed so found this article and tried directives.conf but it not working.
server {
listen 80;
listen 443;
server_name <IP Address>;
return 301 https://www.domain.com$request_uri;
}
We have
OS: CentOS Linux 7.3.1611 (Core)
Product: Plesk Onyx 17.5.3 Update #39
Any help appreciated
Mark
@Mark Collis
Hi!
The configuration you have provided looks valid.
Consider contacting Nginx Support, as they are professionals in their product
Is here a example for append something like this in server {...} for all vhosts? (without service plan)
Hello @Karl,
We do not have examples prepared by us but give a try to this solution: https://github.com/mariusv/nginx-badbot-blocker
Please, note that this was not tested with Plesk and will be done at your own risk.
Thanks for reply, but I don't understand in which way this is a solution? The question was how I can add this lines in quote to all vhost nginx config-files.
/var/www/vhosts/system/domain1.com/conf/vhost_nginx.conf
/var/www/vhosts/system/domain2.com/conf/vhost_nginx.conf
I expected a answer like
# for filename in `find /var/www/vhosts/system/*/conf/ -name vhost_nginx.conf`; do echo $filename; cat add_new_vhost_conf.txt >> $filename; done
offtopic: your link is version 1, current version 3 is this link https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker
Ok @Karl,
Thank you for clarification.
This script appeds the configuration from specified file "add_new_vhost_conf.txt":
#!/bin/bash
plesk db -Ne "select domains.name from domains;" > domains.txt
while read i
do
cat add_new_vhost_conf.txt >> /var/www/vhosts/system/$i/conf/nginx.conf
done < domains.txt
Check it, it case it will not suit, try using "sed" command if adding test will be needed to specific place in configuration.
Also, please note that such manual web server configuration is not recommended and may be overwritten after updates or domains reconfiguration.
Hi, we'd like to globally add these two "include" statements:
include /etc/nginx/bots.d/blockbots.conf;
include /etc/nginx/bots.d/ddos.conf;
If we follow the instructions (above) exactly, an error relating to the blockbots.conf file not being allowed in this location is recieved. That's easy to correct as follows:
server {
include /etc/nginx/bots.d/blockbots.conf;
include /etc/nginx/bots.d/ddos.conf;
}
but although that ^ config is correct (i.e. no nginx errors)... the settings are NOT applied globally, No related changes are visible at all, after re-starting nginx (via curl tests etc).
If instead, we add the 1st version of the above, to 'Additional nginx directives' via Plesk Panel GUi and/or /var/www/vhosts/system/**my-domain**/conf/vhost_nginx.conf via CLI (the 2nd version is - correcty - not permitted) then when tested, via curl afterwards, everything DOES work correctly (on that specific domain) with all of the permitted bots, but the error on all of the banned bots is as follows: curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1).
Obviously, we'd prefer to apply these two "include" statements globally (not individually on each hosted domain...) but creating a /etc/nginx/conf.d/directives.conf file as per above and which includes them - currently - doesn't work. What did we miss? :o))
That last post was a week ago now... Any tech response from Plesk yet?
Ivan Postnikov / Kuzma Ivanov
Why would Plesk publish what are usually very helpful / time saving articles, if, there is then: Zero response to relevant questions relating to the article itself? That seems like a very strange logic?
Ivan Postnikov Kuzma Ivanov
Please sign in to leave a comment.