Vincenzo Ingrosso Weblog
  • System Admin
  • Random Post
  • Authors
  • Become an Author
  • Messages Box
  • Crumbs!
  • Privacy Policy
  • About me
  • Contact
Facebook Page
  • Authors
  • Become an Author
  • Messages Box
  • Crumbs!
  • Privacy Policy
3 Likes
0 Followers
28 Followers
Iscriviti
Vincenzo Ingrosso Weblog
Vincenzo Ingrosso Weblog
  • System Admin
    • Debian & Sysadmin
    • Server
    • Bash
    • Ispconfig
    • Mac OSX
  • Random Post
  • About me
  • Contact
  • Debian & Sysadmin
  • Ispconfig

Snippets: ISPConfig directive for nginx

  • 8 Luglio 2015
  • Vincenzo Ingrosso
Total
0
Shares
0
0
0

Snippets, ovvero ritagli di codice. ISPConfig permette di salvare piccoli frammenti di codice che possono essere richiamati facilmente quando si aggiunge un sito al nostro sistema. Possono essere relativi a PHP, Apache, Proxy o come nel nostro caso a nginx. Quelli che seguono sono alcuni di quelli che uso quando attivo un sito con WordPress.

Sono esempi e vi prego di prenderli per quello che sono: spunti che possono essere più o meno utili a seconda delle necessità.

Disclaimer: Prestate attenzione all’uso di questi o altri snippets. Sovrascrivono le impostazioni di default di ISPConfig e quindi potrebbero compromettere la sicurezza del sistema invece che aumentarla. Un eventuale errore su uno snippet inserito in un sito potrebbe ripercuotersi su tutti gli altri.

 

W3 Total Cache

Questo plugins genera un file nginx.conf nella ROOT directory del vostro sito. Il file contiene varie direttive a secondo del tipo di configurazione da voi scelta. Per includere il file vi basta generare un snippet simile:

include {DOCROOT}/nginx.conf;

 

Security

Alcune direttive di sicurezza generale che possono essere utilizzate con tutti i siti web che ospitate. Nel codice ho salvato i commenti che spiegano a cosa servono le varie parti presenti:

### Prevent access to this file generated by various plugins (W3 Total Cache, AkeebaBackup, etc)
location = /nginx.conf {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
## Block some common exploits
set $common_exploit 0;
if ($query_string ~ "proc/self/environ") {
	set $common_exploit 1;
}
if ($query_string ~ "mosConfig_[a-zA-Z_]{1,21}(=|\%3D)") {
	set $common_exploit 1;
}
if ($query_string ~ "base64_(en|de)code\(.*\)") {
	set $common_exploit 1;
}
if ($query_string ~ "(<|%3C).*script.*(>|%3E)") {
	set $common_exploit 1;
}
if ($query_string ~ "GLOBALS(=|\[|\%[0-9A-Z]{0,2})") {
	set $common_exploit 1;
}
if ($query_string ~ "_REQUEST(=|\[|\%[0-9A-Z]{0,2})") {
	set $common_exploit 1;
}
if ($common_exploit = 1) {
	return 403;
}
## File injection protection
set $file_injection 0;
if ($query_string ~ "[a-zA-Z0-9_]=http://") {
	set $file_injection 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=(\.\.//?)+") {
	set $file_injection 1;
}
if ($query_string ~ "[a-zA-Z0-9_]=/([a-z0-9_.]//?)+") {
	set $file_injection 1;
}
if ($file_injection = 1) {
	return 403;
}
## SQL injection first line of defence (NOT comprehensive!)
set $sql_injection 0;
if ($query_string ~ "concat.*\(") {
	set $sql_injection 1;
}
if ($query_string ~ "union.*select.*\(") {
	set $sql_injection 1;
}
if ($query_string ~ "union.*all.*select.*") {
	set $sql_injection 1;
}
if ($sql_injection = 1) {
	return 403;
}
## Basic anti-spam
set $looks_like_spam 0;
if ($query_string ~ "\b(ambien|blue\spill|cialis|cocaine|ejaculation|erectile)\b") {
	set $looks_like_spam 1;
}
if ($query_string ~ "\b(erections|hoodia|huronriveracres|impotence|levitra|libido)\b") {
	set $looks_like_spam 1;
}
if ($query_string ~ "\b(lipitor|phentermin|pro[sz]ac|sandyauer|tramadol|troyhamby)\b") {
	set $looks_like_spam 1;
}
if ($query_string ~ "\b(ultram|unicauca|valium|viagra|vicodin|xanax|ypxaieo)\b") {
	set $looks_like_spam 1;
}
if ($looks_like_spam = 1) {
	return 403;
}
## User agent blocking
##
## Disables access to your site by user agent. Useful to block some
## bandwidth hoggers.
set $bad_ua 0;

# This also disables Akeeba Remote Control 2.5 and earlier
if ($http_user_agent ~ "Indy Library") {
	set $bad_ua 1;
}

# Disabling Wget will also block the most common method to run CRON jobs
if ($http_user_agent ~ "Wget") {
	set $bad_ua 1;
}

# Common bandwidth hoggers and hacking tools. Each rule is three lines, beginning with "if"
if ($http_user_agent ~ "libwww-perl") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "Download Demon") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "GetRight") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "GetWeb!") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "Go!Zilla") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "Go-Ahead-Got-It") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "GrabNet") {
	set $bad_ua 1;
}
if ($http_user_agent ~ "TurnitinBot") {
	set $bad_ua 1;
}
# If you enable any of the above don't remove this. It's what blocks
# the bad user agents!
if ($bad_ua = 1) { 
	return 403; 
}

 

WordPress Security

Il frammento che segue impedisce l’accesso diretto ad alcuni file di default presenti nell’archivio di WordPress. In particolare come potete notare sono relativi alla localizzazione in italiano:

## Block access to wp-config-sample.php and other WP defaults file
location = /wp-config-sample.php {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /wp-config.php {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /htaccess.txt {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /LEGGIMI.txt {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /license.txt {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /licenza.html {
	log_not_found off;
	access_log off;
	return 404;
	break;
}
location = /readme.html {
	log_not_found off;
	access_log off;
	return 404;
	break;
}

 

Cloudflare

Dal momento che CloudFlare agisce come un proxy inverso, tutte le connessioni provengono da uno degli indirizzi IP CloudFlare. CloudFlare segue gli standard di settore e include l’indirizzo IP di origine nell’intestazione X-Forwarded-For. Può anche essere usata l’intestazione CF-Connecting-IP. Per preservare l’originario IP del visitatore, utilizzare il seguente snippet per nginx:

## CloudFlare support - see https://support.cloudflare.com/hc/en-us/articles/200170706-Does-CloudFlare-have-an-IP-module-for-Nginx-
## IPv4
set_real_ip_from   199.27.128.0/21;
set_real_ip_from   173.245.48.0/20;
set_real_ip_from   103.21.244.0/22;
set_real_ip_from   103.22.200.0/22;
set_real_ip_from   103.31.4.0/22;
set_real_ip_from   141.101.64.0/18;
set_real_ip_from   108.162.192.0/18;
set_real_ip_from   190.93.240.0/20;
set_real_ip_from   188.114.96.0/20;
set_real_ip_from   197.234.240.0/22;
set_real_ip_from   198.41.128.0/17;
set_real_ip_from   162.158.0.0/15;
set_real_ip_from   104.16.0.0/12;
## IPv6
set_real_ip_from   2400:cb00::/32;
set_real_ip_from   2606:4700::/32;
set_real_ip_from   2803:f800::/32;
set_real_ip_from   2405:b500::/32;
set_real_ip_from   2405:8100::/32;
real_ip_header     X-Forwarded-For;

 

Akeeba Backup Pro for WordPress

Se state usando questo plugin avrete bisogno di concedere l’accesso diretto a questo al file riportato nell snippet. Questo esempio può essere utilizzato con qualunque altro file che necessiti del permesso di accesso diretto:

## Advanced server protection rules exceptions
location = /wp-content/plugins/akeebabackupwp/app/restore.php {
	{FASTCGIPASS}
	break;
}
Total
0
Shares
Share 0
Tweet 0
Pin it 0
Related Topics
  • cloudflare
  • ispconfig
  • nginx
  • server
  • snippets
  • wordpress
Vincenzo Ingrosso

Sono un lavoratore in-dipendente. Non ho titoli di studio che possano testimoniare le mie conoscenze in ambito informatico, ma sono dietro una tastiera dal '95. La mia prima distribuzione linux è stata RedHat, per passare nel giro di tre mesi a Slackware con la quale ho convissuto per circa 13 anni. Ad un certo punto ho realizzato Sflack, vale a dire Slackware Linux a 64bit puri, senza quindi utilizzo di multi-lib. Successivamente per mancanza di tempo e per comodità sono passato a Debian. Oggi lavoro davanti ad un iMac, ho una famiglia e mi occupo di tutt'altro.

Articolo Precedente
  • Bash
  • Debian & Sysadmin

uTorrent®: howto install and setup utserver in Debian Wheezy

  • 1 Luglio 2015
  • Vincenzo Ingrosso
Visualizza Post
Articolo Successivo
  • Bash
  • Debian & Sysadmin

WordPress: Disable or Enable All Plugins

  • 9 Luglio 2015
  • Vincenzo Ingrosso
Visualizza Post
You May Also Like
Visualizza Post
  • Bash
  • Debian & Sysadmin
  • Server

Initramfs: install sshd to remote access

  • Vincenzo Ingrosso
  • 17 Luglio 2017
Visualizza Post
  • Bash
  • Debian & Sysadmin
  • Server

OpenVPN: setup guide on Debian (routed and bridged VPN)

  • Vincenzo Ingrosso
  • 22 Luglio 2015
Visualizza Post
  • Bash
  • Debian & Sysadmin
  • Server

Debian: from Wheezy (7.0) to Jessie (8.0)

  • Vincenzo Ingrosso
  • 14 Luglio 2015
Visualizza Post
  • Bash
  • Debian & Sysadmin
  • Server

Intrusion Detection System: Setup Arno’s Iptables Firewall, Port Scan Attack Detector, Firewall Snort

  • Vincenzo Ingrosso
  • 11 Luglio 2015
Visualizza Post
  • Bash
  • Debian & Sysadmin

WordPress: Disable or Enable All Plugins

  • Vincenzo Ingrosso
  • 9 Luglio 2015
Visualizza Post
  • Bash
  • Debian & Sysadmin

uTorrent®: howto install and setup utserver in Debian Wheezy

  • Vincenzo Ingrosso
  • 1 Luglio 2015
Visualizza Post
  • Bash
  • Debian & Sysadmin
  • Ispconfig

Ispconfig : how to migrate from Apache to nginx

  • Vincenzo Ingrosso
  • 17 Ottobre 2014
Visualizza Post
  • Bash
  • Debian & Sysadmin

Fail2Ban: how-to setup with Blocklist reporting

  • Vincenzo Ingrosso
  • 23 Luglio 2014
  • Initramfs: install sshd to remote access

    Visualizza Post
  • OpenVPN: setup guide on Debian (routed and bridged VPN)

    Visualizza Post
  • Debian: from Wheezy (7.0) to Jessie (8.0)

    Visualizza Post
  • Intrusion Detection System: Setup Arno’s Iptables Firewall, Port Scan Attack Detector, Firewall Snort

    Visualizza Post
  • WordPress: Disable or Enable All Plugins

    Visualizza Post
Facebook Page
Instagram
#yamaha #moto #motorcycle #motogp #honda #motorbike #bike #ducati #suzuki #kawasaki #italy #ktm #bikelife #biker #instamoto #racing #bikeporn #photooftheday #instagood #46 #motocross #ride #picoftheday #love #photography #scorpionsports #fabioquartararo #yamahar1 #yamahar1m
#r1 #yamahar1 #r1m #superbike #sbk
#r1m #yamahar1 #yamaha #wer1 #riderich #sportbike #sportbikes #bikersofinstagram #bikerboysofinstagram #sportbikelife #fastbikes #sportbikesaddicts #bikefam
#sportbike #superbikes #yamaharacing #motor #yamahayzfr #kawasakininja #ninja #sportbike #superbikes #yamaharacing #cc #indonesia #motor #yamahayzfr #kawasakininja #ninja
#sportbike #superbikes #yamaharacing #motor #yamahayzfr #kawasakininja #ninja #sportbike #superbikes #yamaharacing #cc #indonesia #motor #yamahayzfr #kawasakininja #ninja #superbikesgram #bmws #motorcycles #panigale #bikers #duke #yamahamotogp #suzukigsxr #riders #vr #bikeporn #rider #ktmduke #racing #italy #agv #instamoto #bikes
Segui
TRENDING POSTS
  • Initramfs: install sshd to remote access
    • 17 Luglio 2017
  • OpenVPN: setup guide on Debian (routed and bridged VPN)
    • 22 Luglio 2015
  • Debian: from Wheezy (7.0) to Jessie (8.0)
    • 14 Luglio 2015
  • Intrusion Detection System: Setup Arno’s Iptables Firewall, Port Scan Attack Detector, Firewall Snort
    • 11 Luglio 2015
  • WordPress: Disable or Enable All Plugins
    • 9 Luglio 2015
Legalese
Licenza Creative Commons

Questo Blog di Vincenzo Ingrosso è distribuito con Licenza Creative Commons Attribuzione - Non commerciale - Condividi allo stesso modo 4.0 Internazionale.
Debian
FOLLOW ME
Facebook 3 Likes
Instagram 0 Followers
Twitter 28 Followers
#yamaha #moto #motorcycle #motogp #honda #motorbike #bike #ducati #suzuki #kawasaki #italy #ktm #bikelife #biker #instamoto #racing #bikeporn #photooftheday #instagood #46 #motocross #ride #picoftheday #love #photography #scorpionsports #fabioquartararo #yamahar1 #yamahar1m
#r1 #yamahar1 #r1m #superbike #sbk
#r1m #yamahar1 #yamaha #wer1 #riderich #sportbike #sportbikes #bikersofinstagram #bikerboysofinstagram #sportbikelife #fastbikes #sportbikesaddicts #bikefam

Let's keep in touch

Subscribe now to my newsletter

about
Vincenzo Ingrosso

About the site

Sono un lavoratore in-dipendente. Non ho titoli di studio che possano testimoniare le mie conoscenze in ambito informatico, ma sono dietro una tastiera dal '95. La mia prima distribuzione linux è stata RedHat, per passare nel giro di tre mesi a Slackware con la quale ho convissuto per circa 13 anni. Ad un certo punto ho realizzato Sflack, vale a dire Slackware Linux a 64bit puri, senza quindi utilizzo di multi-lib. Successivamente per mancanza di tempo e per comodità sono passato a Debian. Oggi lavoro davanti ad un iMac, ho una famiglia e mi occupo di tutt'altro.
Victoria’s Secret

Recent Posts
  • Initramfs: install sshd to remote access
    • 17 Luglio 2017
  • OpenVPN: setup guide on Debian (routed and bridged VPN)
    • 22 Luglio 2015
  • Debian: from Wheezy (7.0) to Jessie (8.0)
    • 14 Luglio 2015
Vincenzo Ingrosso Weblog
  • System Admin
  • Random Post
  • About me
  • Contact
... I follow my passion ...

Inserisci la chiave di ricerca e premi invio.