reverse proxy & web cache

25
REVERSE PROXY & WEB CACHE BY : ELMAHDI BENZEKRI

Upload: el-mahdi-benzekri

Post on 09-Jan-2017

200 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Reverse proxy & web cache

REVERSE PROXY & WEB CACHE

BY : ELMAHDI BENZEKRI

Page 2: Reverse proxy & web cache

Proxy vs Reverse Proxy

Page 3: Reverse proxy & web cache

Reverse proxy in 4 questions – What is a reverse proxy ?• Bridge between the local entreprise network and the

external.• Avoid to expose frontal servers.• Intended to be securized and to absorb large loads of

traffic.

Page 4: Reverse proxy & web cache

Reverse proxy in 4 questions – What are it’s additionnal features?• Access logs• Cache • Load balancing• Data compression, firewall• Authentication and SSL encryption

Page 5: Reverse proxy & web cache

Reverse proxy in 4 questions – Can reduce the complexity of a web architecture?• Yes.

Page 6: Reverse proxy & web cache

Reverse proxy in 4 questions – Can reduce the complexity of a web architecture?• Yes.• All the requests pass trough => uniform error pages,

access logs..• Expose only one address to the external

Page 7: Reverse proxy & web cache

Reverse proxy in 4 questions – What are the most used reverse proxy?• Depending of the majoritary web server• Free• Nginx• Apache• Squid• HAProxy

• Proprietary• Microsoft ISA Server• Big IP

• Traffic management appliances that also fulfill this task : F5 network, Cisco…

Page 8: Reverse proxy & web cache
Page 9: Reverse proxy & web cache

NGINX• Global syntax• C10K problem• Open source writen in 2002 in C by Igor Sysoev

<section> {<directive> <parameters>}

Page 10: Reverse proxy & web cache

Apache HTTPD• Hyper Text Transfer Protocol Daemon• <> Tomcat• The most popular (39% in 2015)• Writen in C In 1995 as ad-on to NCSA HTTPd• Version 2 comes with lot of features

Page 11: Reverse proxy & web cache

Apache vs Nginx - Connection handeling architecture• Apache httpd provide multi processing modules• mpm_prefork• mpm_worker• mpm_event

• Nginx asynchronous, non blocking, event driver connection • One master and several worker processes

Page 12: Reverse proxy & web cache

Apache vs Nginx - Connection handeling architecture

Page 13: Reverse proxy & web cache
Page 14: Reverse proxy & web cache

Web caching management• Improved responsiveness• Increased performance on the same hardware• Availability of content during network interruptions

Page 15: Reverse proxy & web cache

Web caching management• Caching

headers:• Expires• Cache-Control• Etag• Last-Modified• Content-Length

• Cache-Control flag• No-cache• No-store

• What cannot be cached ?• Dynamic pages• Content with authentication cookie• Content linked to user or cart…

• Terminology• Origin server• Cache hit ratio• Stale content• Validation• invalidation

Page 16: Reverse proxy & web cache

Web caching management - nginx• proxy_cache_valid any 10m;• proxy_cache_path /var/www/cache levels=1:2 keys_zone=my-cache:8m

max_size=1000m inactive=600m;• proxy_temp_path /var/www/cache/tmp;• proxy_cache_use_stale error timeout updating http_500 http_502 http_503

http_504;

• Location /{• Proxy_cache my-cache

• }

Page 17: Reverse proxy & web cache

Web caching management- varnish• By Paul Henning

Kamp(FreeBSD dev) in 2006• Reverse proxy cache

server• http processor• Optimized for Linux• Custom configuration

langage

Page 18: Reverse proxy & web cache

Web caching management- varnishDAEMON_OPTS="-a :6081 \ -T localhost:6082 \ -f /etc/varnish/default.vcl \ -S /etc/varnish/secret \ -s malloc,256m“Subroutines :• sub vcl_recv {}• sub vcl_hash {}• sub vcl_backend_response {}• sub vcl_deliver {}…

Request and response VCL object:• Req, bereq,beresp,resp,obj

Return in each subroutine : • Return(pass)• Return(fetch)• Return(deliver)• …

Page 19: Reverse proxy & web cache

Load balancing• Traffic is intelligently distributed amongst multiple servers(app instances)• Features

• Optimizing resource utilization• Reducing latency• Ensuring fault tolerance

• Some load balancing solutions• Open source

• Nginx• Haproxy

• Corporate Standard• F5• Citrix

Page 20: Reverse proxy & web cache

Load balancing - comparisonNGINX HAPROXYONLY HTTP TCP BASED On request health check Out of band health checkThree algorithmes Multiple algorithmesComplicated tasks based on HTTP infos -HTTP2 & SSL in v 1,9 Only in dev versionFree & commercial version Free

Page 21: Reverse proxy & web cache

Load balancing with Nginx• Load balancing methods• Round robin• Least connected• Ip-hash

• Session persistence• Weighted load balancing• Health check(passive)

Page 22: Reverse proxy & web cache

Optimizing Nginx • Number of workers

• grep processor /proc/cpuinfo | wc –l• Worker_connections

• Ulimit –u• Limiting the Buffer size

• client_header_buffer_size 1k;• client_max_body_size 8m;• large_client_header_buffers 2 1k;

• Timeouts • client_body_timeout 12;• client_header_timeout 12;• keepalive_timeout 15;

• Gzip compression

Page 23: Reverse proxy & web cache

DEMO• 2 Tomcat • Nginx > tomcat• Nginx if / break / set / rewrite• Nginx headers• Nginx cache• Nginx log + blacklist• Nginx > 2tomcat• Nginx > varnish > tomcat

Page 24: Reverse proxy & web cache

DEMO

TOMCAT A

TOMCAT B

Page 25: Reverse proxy & web cache

THANK U