• 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 Where to put apache and nginx global rewrite rules?

tkalfaoglu

Silver Pleskian
I have this code for our main site to stop the pesky crawlers in our main site's hosting settings:

Apache & nginx Settings for kalfaoglu.net :

Code:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (SemrushBot|PetalBot|DotBot|gumgum-bot|postmanruntime|ag_dm_spider|scrapy|chimebot|trendkite-akashic-crawler|ZoominfoBot|Sogou|ALittle|Keybot|Buck|curl|webpr
osbot|RestSharp|Snap|SemrushBot|AhrefsBot|DataForSeoBot|Sogou|trendkite-akashic-crawler|cortex|ALittle|Go-http-client|RestSharp) [NC]
RewriteRule .* - [F,L]

and for nginx:

Code:
if ($http_user_agent ~ (SemrushBot|PetalBot|DotBot|gumgum-bot|postmanruntime|ag_dm_spider|scrapy|chimebot|trendkite-akashic-crawler|ZoominfoBot|Sogou|ALittle|Keybot|Buck|curl|webprosbot|RestSharp|Snap|SemrushBot|AhrefsBot|Da
taForSeoBot|Sogou|trendkite-akashic-crawler|cortex|ALittle|Go-http-client|RestSharp|MJ12bot)) {
        return 403;
}

I would like to make this applied to all sites we host. How do I go about making this globally for every site we host/will host?

Many thanks, -t
 
You could put those directives in your own file in /etc/httpd/conf.d and /etc/nginx/conf.d
Use a filename like "zzz_mytweaks.conf" or similar to make sure it is included as the last file
 
Many thanks! I created that zzz_mytweaks.conf, did a httpdmng --reconfigure-domain, but I do not see my changes in the vhost.conf of that domain. Am I suppose to see them there? I mean, how can I tell if my conf is included in the httpd conf?
 
Many thanks! I created that zzz_mytweaks.conf, did a httpdmng --reconfigure-domain, but I do not see my changes in the vhost.conf of that domain. Am I suppose to see them there? I mean, how can I tell if my conf is included in the httpd conf?
In fact, I don't see it anywhere in the /etc/httpd (recursively searched) or in /var/www/vhosts/kalfaoglu.net/conf directories.. I only see it my zzz_mytweaks file. Shouldn't I see it in my kalfaoglu.net conf files too?

Thanks!
 
Shouldn't I see it in my kalfaoglu.net conf files too?

Nope, you won't see those files anywhere except where you've created them (/etc/httpd/conf.d/zzz_mytweaks.conf and/or /etc/nginx/conf.d/zzz_mytweaks.conf)
Once you've created them, a simple reload of Apache + nginx is enough

Note: If you're on Debian or Ubuntu, the Apache global config is in /etc/apache2/conf.d

See also: Apache and Nginx Configuration Files
 
Back
Top