apache as a reverse proxypeople.apache.org/~jim/apachecons/apachecon2004/pdf/tu02.pdf · what is a...

24
Apache as a Reverse Proxy Daniel López Ridruejo [email protected]

Upload: hoangmien

Post on 02-Jul-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Apache as aReverse Proxy

Daniel López [email protected]

Page 2: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

About me

� Open source: Author of mod_mono, Comanche, several Linux Howtos and the Teach Yourself Apache 2 book

� Company: founder of BitRock, multiplatform installers and management software

Page 3: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

About this presentation

� Introduction to proxies� Apache mod_proxy architecture and configuration� Usage scenarios

� Performance� Availability� Management� Security

� Common Issues� Resources

Page 4: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

What is a Proxy?

� HTTP Proxy server : Issues HTTP requests on behalf of clients

� Forward Proxy : Security, Monitoring, Performance

Forward Proxy

ClientsServer

Page 5: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

What is a Reverse Proxy?

Proxy is in front of the servers, transparent to the clients

Reverse ProxyClient Servers

Page 6: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Apache Proxy Architecture (1)

� Implemented as a module� Multiple backends: HTTP, FTP, CONNECT…� Interacts with other Apache modules : SSL,

URL mapping, Compression, Caching� Apache 2.0 : Filtering architecture� Apache 2.1 : Improved caching, new features

(load balancing, AJP protocol)

Page 7: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Apache Proxy Architecture (2)

HTTP

FTP

CONNECT

AJP

mod_proxy

deflateSSL SSLetc

…..etc

…..

Page 8: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Related modules

� mod_cache� mod_ssl� mod_deflate� mod_headers� mod_charset_lite� mod_injection� mod_proxy_add_forward

� mod_ext_filter� mod_rewrite� mod_proxy_html� mod_replace� mod_ip_forward (1.3)� mod_proxy_add_uri� many others...

Page 9: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Compiling mod_proxy

� Use APXS or enable support at compile-time: --enable-proxy--enable-proxy-connect--enable-proxy-ftp--enable-proxy-http--enable-proxy-balancer (2.1)--enable-proxy-ajp (2.1)

Page 10: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Configuration

� Load appropriate modulesLoadModule proxy_module modules/mod_proxy.soLoadModule proxy_http_module modules/proxy_http.soetc…

� Does not need ProxyRequests On� Security/Spam implications

Page 11: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Configuration : Basic Scenario

ProxyPass /downloads http://downloads.example.com(or inside <Location /downloads>)

GET /download/file.exe HTTP/1.1 Host: www.example.com

turns intoGET /file.exe HTTP/1.1Host: downloads.example.com

Problems : redirections, self-referential URLs, absolute paths. Need to rewrite URLs in HTTP responses

Use “!” not to proxy certain URLs

Page 12: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Hiding backend server

� ProxyPassReverseProxyPassReverse /downloads http://downloads.backend.com

� ProxyErrorOverride� mod_proxy_html, mod-replace, rewrite

embedded URLs on the fly� ProxyPassReverseCookiePath� ProxyPassReverseCookieDomain

Page 13: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Client Information Loss

� Client Information : IP, hostname, port, SSL information…

� Server informationThis is added/can be added to headers and

passed to the backend server. Apache 1.3 requires third party modules to do this

X-Forwarded-*, ProxyPreserveHost, etc.

Page 14: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

New functionality in 2.1

� Load Balancer� BalancerMember� ProxySet� ProxyStatus

� Support for AJP protocol� Communicate with Tomcat or any other engine

that supports the protocol

Page 15: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

mod_rewrite

� Advanced URL manipulation, allows [P] option for reverse proxying

� Simple load balancing example :RewriteMap SERVERS rnd:/Library/Services/Apache/conf/servers.conf <Location /webapp> RewriteEngine OnRewriteCond "%{HTTP_COOKIE}" "(^|;\s*)jsessionid=\w*\.(\w+)($|;)“RewriteRule "(.*)" "http://${SERVERS:%2}%{REQUEST_URI}" [P,L]RewriteRule "^.*;jsessionid=\w*\.(\w+)($|;)” "http://${SERVERS:$1}%{REQUEST_URI}“

[P,L]RewriteRule "(.*)" "http://${SERVERS:ALL}%{REQUEST_URI}" [P,L]</Location>

(Full details at http://wiki.apache.org/cocoon/LoadBalancingWithModProxy)

Page 16: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Scenarios

� Performance� Caching� SSL� Slow clients

� Management� Unified URL space� Logging� Troubleshooting

� Security� Interception� Single sign-on� Isolation

� Availability� Load balancing

� Fancy stuff

Page 17: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Performance / Scalability

� SSL processing� Dealing with slow clients, lingering_close� Can be more easily optimized/tuned� Caching� Serve static content locally, proxy rest

Page 18: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Management

� Unified URL Space� Unified Logging� Unified User Tracking� Standardized front end

Page 19: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Security

� Single sign-on� Isolation� Interception : HTTP-level firewall

� Protect unpatched backend servers

Page 20: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Availability

� Apache 2.1 includes mod_proxy_balancer� Smart load-balancers thru custom modules,

mod_rewrite, etc.

Page 21: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Fancy stuff

� Reverse Proxy + filtering architecture, lots of interesting possibilities

� Check/transform content on the fly� Server Side Includes� XSLT transformations� Fixing broken apps/clients� Antivirus

Page 22: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Online resources

� Apache Docs� http://httpd.apache.org

� mod_proxy_html � http://apache.webthing.com � http://www.apacheweek.com/features/reverseproxies

� mod_rewrite guide (dated but relevant)� http://httpd.apache.org/docs/misc/rewriteguide.html

� mod_replace� http://sourceforge.net/projects/mod-replace/

� http://modules.apache.org� http://d-srv.com/modules_for_apache2.html

Page 23: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Related sessions

� TU10: mod_proxy multi protocol framework for httpd-2.0

Also useful� WE16: HTTP Caching and Cache-busting for

Content Publishers� TU18, TU22 : mod_rewrite

Page 24: Apache as a Reverse Proxypeople.apache.org/~jim/ApacheCons/ApacheCon2004/pdf/TU02.pdf · What is a Proxy? HTTP Proxy server : Issues HTTP requests on behalf of clients Forward Proxy

Q&A

Thanks for your time!

More info:http://www.apacheworld.org/apachecon/

You can reach me at:[email protected]