This document discusses using Nginx as a web server and content accelerator. It provides two examples of how to configure Nginx for acceleration. The first example shows configuring Nginx with PHP-FCGI to accelerate PHP content. The second example demonstrates configuring Nginx to proxy requests to an Apache server running PHP in the backend. Additional sections cover using Nginx as a cache, examples of caching configurations, and provisioning cache nodes across multiple servers.
15. Caché
Primer ejemplo
upstream local ! ! { server 127.0.0.1:8080; }
upstream mendozaaaa ! server 200.57.34.35:80;
{
server 200.57.34.45:80; } #c.w.h
upstream mozillamexico ! { server 200.57.34.35:80;
server 200.57.34.45:80; } #c.w.h
upstream enli! ! ! { server 200.57.34.35:80;
server 200.57.34.45:80; } #c.w.h
Thursday, October 25, 2012
21. Caché
Primer ejemplo
server {
! listen 80;
! server_name ! enli.org.mx ;
! access_log /var/log/nginx/accounting.log accounting;
! location / {
! ! rewrite ^/(.*)$ http:/ /www.$server_name/$1 permanent;
! }
! include /etc/nginx/common-attack.conf;
}
Thursday, October 25, 2012
22. Caché
CDN por DNS Round Robin
;$TTL 3600! ; 1 hour
$TTL 300! 5 min
;
$ORIGIN cdn.1-1-0-1.net.
;A
;a! ! A! 50.30.46.179 ; raicilla
;a! ! A! 99.90.100.1 ; Nodo A
a! ! A! 99.90.100.2 ; Nodo D
;a! ! A! 200.57.48.12 ; Nodo C
;a! ! A! 200.57.48.13 ; Nodo E
a! ! A! 74.86.74.194 ; Nodo F
Thursday, October 25, 2012
23. Caché
Provisionamiento de nodos
for i in `cat hosts | sed “s/#.*$/ ` ; do
/”
ssh $i < scripts/install-key
./scripts/install-node $i
done
./sync-nginx-all
Thursday, October 25, 2012
24. Caché
sync-nginx-all
RSYNC_PARAMS='-vacH --progress '
for i in `cat ./hosts | sed 's/#.*$/ ; do
/'`
! echo "===> rsync to: $i"
! rsync $RSYNC_PARAMS ./etc/nginx/*conf root@$i:/etc/nginx/
! rsync $RSYNC_PARAMS --delete ./etc/nginx/vhosts/ root@$i:/etc/nginx/vhosts/
! ssh root@$i service nginx reload
done
Thursday, October 25, 2012
25. Caché
common-attack.conf
#Apache .htaccess
location ~ /.ht {
! deny all;
}
## Only allow these request methods ##
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
## Do not accept DELETE, SEARCH and other methods ##
#Directory trasversal ../../../../../
! if ($query_string ~ ../../../../../ ) {
! ! return 404;
! }
location ~ url(data:image/png;base64, {
! return 404;
}
Thursday, October 25, 2012