Posts Tagged apache2

Apache2 – mod_evasive

Vediamo come prevenire attacchi DDOS con questo modulo di apache:

# up2date -i httpd-devel
# cd /usr/local/src
# wget http://www.zdziarski.com/blog/wp-content/uploads/2010/02/mod_evasive_1.10.1.tar.gz
# tar -zxvf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# /usr/sbin/apxs -cia mod_evasive20.c

Adesso aggiungiamo quanto segue in /etc/apache2/apache2.conf

<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 5
DOSSiteCount 100
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 600

</IfModule>

# /etc/init.d/apache2 restart

Share

, ,

No Comments

Apache2: nascondere informazioni generali e versione di PHP

Per prima cosa editare /etc/apache2/apache2.conf e aggiungere le seguenti 2 direttive:

ServerTokens ProductOnly
ServerSignature Off

Adesso sitemiamo anche il php editando i seguenti files/etc/php5/apache2/php.ini e /etc/php5/cli/php.ini e modificando in entrambi i files:

expose_php On

in

expose_php Off

/etc/init.d/apache2 restart

Share

, , ,

No Comments

Nginx & Ubuntu 10.04 – SSL reverse proxy

Ho sempre preferito HAproxy nel vasto (nemmeno troppo) panorama dei reverse-proxy fino a quando non mi sono accorto che non č in grado di gestire nativamente i certificati ma č necessaria l’implementazione di STunnel, ovvero, secondo me, di un accrocchione epico. Qui di seguito vedremo come implementare NGiNX con supporto SSL attivo.

Recuperiamo tutto il software necessaio alla compilazione:
sudo aptitude -y install build-essential
sudo aptitude -y install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev

Recuperiamo i sorgenti e compiliamo:

cd /usr/src/
wget http://nginx.org/download/nginx-1.0.6.tar.gz
tar zvxf nginx-1.0.6.tar.gz
cd nginx-1.0.6
./configure --sbin-path=/usr/local/sbin --with-http_ssl_module
make && make install

Creiamo lo script di init:

nano /etc/init.d/nginx

e mettiamo al suo interno quanto segue:

#!/bin/sh

### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx rProxy server
# Description: starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
. /etc/default/nginx
fi

set -e

case "$1" in
start)
echo -n "Starting $DESC: "
start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;

restart|force-reload)
echo -n "Restarting $DESC: "
start-stop-daemon --stop --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON
sleep 1
start-stop-daemon --start --quiet --pidfile \
/usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
--exec $DAEMON
echo "$NAME."
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac

exit 0

rendiamolo esguibile all’avvio del server:

sudo chmod +x /etc/init.d/nginx
sudo /usr/sbin/update-rc.d -f nginx defaults

creiamo la struttura in apache style per gestire i vhosts:

sudo mkdir /usr/local/nginx/sites-available
sudo mkdir /usr/local/nginx/sites-enabled

modifichiamo nginx.conf e cancelliamo tutto il suo contenuto:

echo " " > /usr/local/nginx/conf/nginx.conf

e mettiamo al suo interno:

user www-data www-data;
worker_processes 4;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;

sendfile on;
tcp_nopush on;
tcp_nodelay off;
keepalive_timeout 5;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml
application/xml+rss text/javascript;

include /usr/local/nginx/sites-enabled/*;
}

e adesso creiamo il nostro virtual host:

nano /usr/local/nginx/sites-available/sito.com

e mettiamo al suo interno:

upstream sito_com {
server web1:81;
server web2:81;
}

server {

listen 443;

ssl on;
ssl_certificate /etc/ssl/sito.com.crt;
ssl_certificate_key /etc/ssl/sito.com.key;

server_name sito.com;

location / {

# needed to forward user's IP address backendS
proxy_set_header X-Real-IP $remote_addr;

# needed for HTTPS
#proxy_set_header X_FORWARDED_PROTO https;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_max_temp_file_size 0;

proxy_pass http://sito_com;

} #end locationy

} #end server

e attiviamo il vhosts:

sudo ln -s /usr/local/nginx/sites-available/sito.com /usr/local/nginx/sites-enabled/sito.com

ovviamente web1 e web2 sono i backend e avranno un ip in /etc/hosts del server, inoltre i backend avranno un vhost di apache sito.com in ascolto sulla porta 81.

Adesso creiamo dei certificati giusto per provare che il tutto funzioni a dovere:

cd /etc/ssl
openssl genrsa -des3 -out sito.com.key 1024
openssl req -new -key sito.com.key -out sito.com.csr
cp sito.com.key sito.com.key.bak
openssl rsa -in sito.com.key.bak -out sito.com.key

/etc/init.d/nginx restart

restartiamo il proxy e siamo pronti per testare il nostro proxy puntando il browser su https://sito.com

that’s all folks

Share

, , , , , , ,

No Comments