Archives de catégorie : Apache2

Check DDOS Apache

#!/bin/bash

export LANG="POSIX"

# Get parameters
warning=${1:-"50"}
critical=${2:-"100"}
log_file=${3:-"*access_log"}
pattern=$4

# Get current hour
hour=$(date +%d/%b/%Y:%H -d '1 hours ago')

grep "$hour" /var/log/httpd/${log_file} | awk -v WARNING="${warning}" -v CRITICAL="${critical}" -v pattern="${pattern}" '

$0 ~ pattern {
  counter[$1]++
}

END {
  for (ip in counter) {
    if (counter[ip] > CRITICAL) {
	print "2";
	exit;
    } else if (counter[ip] > WARNING) {
	print "1";
	exit;
    }
  }
  print "0"
}

'

Apache2

Consommation moyenne en RAM

ps aux | grep apache2 | grep -v pts | awk '{ tot += $6; procs += 1; print $2,$6,$11 } END { print "TOTAL: ",tot,"/",procs,"=",tot/procs }'

Apache https proxy pass

( client ⇒ https ⇒ apache ⇒ http ⇒ backend )

<VirtualHost *:443>

    ServerName blablab.com

    SSLEngine on
    SSLCertificateFile "/etc/ssl/site/public.crt"
    SSLCertificateKeyFile "/etc/ssl/site/private.pem"
    SSLCertificateChainFile "/etc/ssl/site/intermediate.crt"
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5

    ErrorLog ${APACHE_LOG_DIR}/site-error.log
    CustomLog ${APACHE_LOG_DIR}/site-access.log combined


    ProxyRequests Off
    ProxyPreservehost On
    <Proxy *>
#        Order deny,allow
#        Allow from all
        Require all granted
    </Proxy>

    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
    <Location />
        Order allow,deny
        Allow from all
    </Location>

</VirtualHost>

<VirtualHost *:80>

    ServerName blablab.com

    Redirect permanent / https://blablab.com/

 <IfModule mod_rewrite.c>
	RewriteEngine on
	RewriteCond %{REQUEST_METHOD} ^{TRACE|TRACK}
	RewriteRule .* - [F]
 </IfModule>

</VirtualHost>