Painless Web Proxying with Apache mod_proxy



Similar documents
Apache httpd v2.4: Reverse Proxy. (The Hidden Gem) Jim Jagielski

What's new in httpd 2.2?

Apache HTTP Server. Load-Balancing with Apache HTTPD 2.2 and later. Erik Abele

Apache Tomcat. Load-balancing and Clustering. Mark Thomas, 20 November Pivotal Software, Inc. All rights reserved.

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

Apache 2.2 and mod_proxy_balancer

Apache Tomcat & Reverse Proxies

Intro to Load-Balancing Tomcat with httpd and mod_jk

What s new in Apache HTTP Server 2.2. Jim Jagielski jim@jagunet.com

The mod_proxy Cookbook

1. Introduction 2. Getting Started 3. Scenario 1 - Non-Replicated Cluster 4. Scenario 2 - Replicated Cluster 5. Conclusion

Setting Up B2B Data Exchange for High Availability in an Active/Active Configuration

Apache Tomcat. Tomcat Clustering: Part 2 Load balancing. Mark Thomas, 15 April Pivotal Software, Inc. All rights reserved.

Oracle9i Application Server: Options for Running Active Server Pages. An Oracle White Paper July 2001

An Esri White Paper January 2010 Performance and Throughput Tips for ArcGIS Server Cached Map Services and the Apache HTTP Server

mod_cluster A new httpd-based load balancer Brian Stansberry JBoss, a division of Red Hat

Apache Performance Tuning

EQUELLA. Clustering Configuration Guide. Version 6.2

Technical specification

Implementation of Web Application Firewall

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP LTM with Apache Tomcat and Apache HTTP Server

Reverse Proxy Guide. Version 2.0 April 2016

Agenda. Tomcat Versions Troubleshooting management Tomcat Connectors HTTP Protocal and Performance Log Tuning JVM Tuning Load balancing Tomcat

Content Transformation with Apache

Configuring Nex-Gen Web Load Balancer

HAProxy. Ryan O'Hara Principal Software Engineer, Red Hat September 17, HAProxy

Configuring Remote HANA System Connection for SAP Cloud for Analytics via Apache HTTP Server as Reverse Proxy

White Paper DEPLOYING WDK APPLICATIONS ON WEBLOGIC AND APACHE WEBSERVER CLUSTER CONFIGURED FOR HIGH AVAILABILITY AND LOAD BALANCE

By PANKAJ SHARMA. Concepts of Server Load Balancing

Scaling Progress OpenEdge Appservers. Syed Irfan Pasha Principal QA Engineer Progress Software

Implementing Reverse Proxy Using Squid. Prepared By Visolve Squid Team

Deployment Guide Microsoft IIS 7.0

PROXY SETUP WITH IIS USING URL REWRITE, APPLICATION REQUEST ROUTING AND WEB FARM FRAMEWORK OR APACHE HTTP SERVER FOR EMC DOCUMENTUM EROOM

Accelerating Rails with

Welcome to Apache the number one Web server in

EQUELLA. Clustering Configuration Guide. Version 6.0

Apache and Tomcat Clustering Configuration Table of Contents

HAProxy. Free, Fast High Availability and Load Balancing. Adam Thornton 10 September 2014

DEPLOYMENT GUIDE Version 1.0. Deploying the BIG-IP Edge Gateway for Layered Security and Acceleration Services

IERG 4080 Building Scalable Internet-based Services

The course will be run on a Linux platform, but it is suitable for all UNIX based deployments.

Deployment and Monitoring. Pascal Robert MacTI

High Availability Low Dollar Load Balancing

mod_cluster Documentation

Load Balancing and Sessions. C. Kopparapu, Load Balancing Servers, Firewalls and Caches. Wiley, 2002.

CentraSite SSO with Trusted Reverse Proxy

LOAD BALANCING TECHNIQUES FOR RELEASE 11i AND RELEASE 12 E-BUSINESS ENVIRONMENTS

Single Pass Load Balancing with Session Persistence in IPv6 Network. C. J. (Charlie) Liu Network Operations Charter Communications

Network and Scalability Whitepaper

HTTPS HTTP. ProxySG Web Server. Client. ProxySG TechBrief Reverse Proxy with SSL. 1 Technical Brief

Apache Tomcat Clustering

DMZ Network Visibility with Wireshark June 15, 2010

Understanding Evolution's Architecture A Technical Overview

Prerequisites. Creating Profiles

Proxy Server, Network Address Translator, Firewall. Proxy Server

Barracuda Load Balancer Online Demo Guide

Configuring Load Balancing

Apache Tomcat Tuning for Production

Administering mod_jk. To Enable mod_jk

IBM Tivoli Composite Application Manager for Microsoft Applications: Microsoft Internet Information Services Agent Version Fix Pack 2.

Cookbook Secure Failover for Tomcat Application Server Use Apache, mod_proxy, mod_security, mod_ssl to offer secure application delivery

SpagoBI Tomcat Clustering Using mod_jk and httpd on Centos - In-Memory Session Replication.

How To Configure Apa Web Server For High Performance

Deployment Guide. AX Series with Microsoft Exchange Server

SIIT-DC: Stateless IP/ICMP Translation for IPv6 Data Centre Environments & SIIT-DC: Dual Translation Mode

CA SiteMinder Secure Proxy Server

Outline VLAN. Inter-VLAN communication. Layer-3 Switches. Spanning Tree Protocol Recap

Configuring DNS. Finding Feature Information

PeopleSoft Online Performance Guidelines

WebBridge LR Integration Guide

CA SiteMinder Secure Proxy Server

ALOHA LOAD BALANCER MANAGING SSL ON THE BACKEND & FRONTEND

Nginx 1 Web Server Implementation

Introducing the Microsoft IIS deployment guide

WAN Optimization, Web Cache, Explicit Proxy, and WCCP. FortiOS Handbook v3 for FortiOS 4.0 MR3

PRODUCT VERSION: LYNC SERVER 2010, LYNC SERVER 2013, WINDOWS SERVER 2008

FortiOS Handbook - Load Balancing VERSION 5.2.2

Rails Application Deployment. July Philly on Rails


Reverse Proxy with SSL - ProxySG Technical Brief

CS 188/219. Scalable Internet Services Andrew Mutz October 8, 2015

Load Balancing Web Applications

Deployment Guide. AX Series with Microsoft Office SharePoint Server

Understanding Slow Start

1. When will an IP process drop a datagram? 2. When will an IP process fragment a datagram? 3. When will a TCP process drop a segment?

Deployment Guide Oracle Siebel CRM

The Windows Web Platform. Michael Epprecht Microsoft Switzerland twitter: fastflame

Repeater. BrowserStack Local. browserstack.com 1. BrowserStack Local makes a REST call using the user s access key to browserstack.

Security. TestOut Modules

Shibboleth SP Simple Installation Guide For LINUX

WebAccelerator Administration Guide

Apache As A Malware Scanning Proxy. Jeremy Stashewsky, Sophos Plc. jeremys@ca.sophos.com

Description of Microsoft Internet Information Services (IIS) 5.0 and

How To Balance A Load Balancer On A Server On A Linux (Or Ipa) (Or Ahem) (For Ahem/Netnet) (On A Linux) (Permanent) (Netnet/Netlan) (Un

Deploying F5 with Microsoft Forefront Threat Management Gateway 2010

Application Note. Lync 2010 deployment guide. Document version: v1.2 Last update: 12th December 2013 Lync server: 2010 ALOHA version: 5.

Transcription:

Painless Web Proxying with Apache mod_proxy Justin R. Erenkrantz University of California, Irvine and Google, Inc. http://www.erenkrantz.com/oscon/ justin@erenkrantz.com

Why should I pay attention? Apache HTTP Server committer since 2001 Also involved with APR and Subversion Director, Apache Software Foundation Engineering Intern, Google, Inc. Ph.D. student at UC Irvine 2

Forward Proxy example.com Internet Forward Proxy Server Some other website Multiple clients route all HTTP traffic through the same outgoing server 3

Reverse Proxy / Gateway V240 Internet V240 Reverse Proxy Server V240 Distributes incoming requests to multiple identical backends 4

mod_proxy Goals Squid is a fully featured HTTP forward proxy cache - suitable for a workgroup, etc. mod_proxy + mod_cache can do a passable job as a forward caching proxy, but that hasn t been a main focus of recent work Recent work on mod_proxy is aimed at serving the needs of reverse proxies 5

What is Apache HTTP Server? Derived from NCSA httpd Best web server money can t buy Over 60% market share - Netcraft Extensible, modular architecture Has built-in support for forward and reverse proxies 6

Apache HTTP Server History 1.0 released in December, 1995 1.3.0 released in June, 1998 2.0.35 (first 2.0 GA) released April, 2002 2.2.0 released December, 2005 2.2.2 released May, 2006 7

Overview of 2.x Features 2.0 was a major architectural rewrite Provides a solid platform for further work Introduction of APR abstracts OS details Threadable MPMs = lower memory footprint Filters bridge a long-time gap present in 1.x IPv6 support, mod_ssl & mod_dav bundled 8

mod_proxy s History mod_proxy has an unusual history First included in 1.1 (circa 1996) Punted when 2.0 started as it was broken Came back just in time for 2.0 GA Rewritten for 2.2 with load balancing Is the third time the charm? We hope. 9

mod_proxy Supported Protocols HTTP/0.9, HTTP/1.0, HTTP/1.1 SSL traffic via mod_ssl AJP13 - Tomcat s mod_jk protocol FTP (only supports GET) CONNECT (SSL Proxying) FastCGI support currently in trunk (2.3+) 10

Configuring a Forward Proxy Listen 3128 ProxyRequests on <Proxy *> Order Deny,Allow Deny from all Allow from 192.168.0 </Proxy> Then, configure your browser to use http://proxy.example.com:3128/ All requests made by your local browser will be relayed to the forward proxy. No direct connections to the outside world will be made. 11

What is load balancing? V240 Internet V240 Reverse Proxy Server V240 Distribute load to several identical servers Gateways are transparent to external users 12

Load balancing in mod_proxy Pluggable module to balance load across all available backends: mod_proxy_balancer Request counting (round-robin) Weighted traffic average (based on bytes) A user can be sticky to a backend based on cookies (JSESSIONID, PHPSESSIONID) 13

Backend optimizations mod_proxy supports connection pooling Connections are shared within a process Useful if using worker or event MPM Backends can be added or removed while the system is online through the balancermanager interface 14

Reverse Proxy Example Connection reuse: ProxyPass /example http://backend.example.com min=0 max=20 smax=5 ttl=120 retry=300 ProxyPassReverse /example http://backend.example.com/ Option Description Default min Minimum number of connections to keep open 0 max Maximum connections to keep open to server 1 or n* smax (Soft maximum) Try to keep this many connections open max ttl Time to live for each connection above smax none retry If conn. fails, wait this long before reopening conn. 60 sec * = If threaded MPM, use ThreadsPerChild; otherwise 1 16

Serve from front-end directly ProxyPass /images! ProxyPass /css! ProxyPass / http://backend.example.com ProxyPass with! is useful when you have static content (images, CSS, etc.) Avoids the overhead of going to the backend 17

AJP / mod_proxy_ajp httpd 2.2+ can talk to Tomcat natively! Built-in bundled module to replace mod_jk No external modules needed with 2.2 Configure Tomcat to listen on the AJP port Set up Tomcat like you would with mod_jk 18

mod_proxy AJP Example ProxyPass / balancer://example/ <Proxy balancer://example/> BalancerMember ajp://server1/ BalancerMember ajp://server2/ BalancerMember ajp://server3/ </Proxy> The only difference is we replace http with ajp. mod_proxy and mod_proxy_ajp does the rest. 19

FastCGI Usually recommended with Ruby on Rails Avoids the overhead of spawning new CGI processes on each request FastCGI daemon with a custom binary protocol listener on port 8000 Only in httpd s trunk (2.3+) - may be backported to 2.2.x, but not sure yet. 20

mod_proxy FastCGI Example ProxyPass / balancer://example/ <Proxy balancer://example/> BalancerMember fcgi://server1/ BalancerMember fcgi://server2/ BalancerMember fcgi://server3/ </Proxy> Again, the only difference is we replace http with fcgi. 21

Your own protocol handler... FTP and other protocols also supported by just replacing the URI scheme What if you want to create your own protocol handler for mod_proxy? It s not that bad...almost. Let s use mod_proxy_fcgi as our example... 22

Walking tour of mod_proxy_fcgi mod_proxy_fcgi is a good example to learn from because it has been written relatively recently and can take clear advantage of the new features of mod_proxy. It will just send the requests to the FastCGI daemon and receive a response. Source: http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/proxy/mod_proxy_fcgi.c % wc -l mod_proxy_fcgi.c 998 mod_proxy_fcgi.c Exists only in trunk. mod_proxy_fcgi be backported to 2.2.x in the future... All of the logic responsible for talking to FastCGI is self-contained to this one module and one file. 23

Apache module terminology Directive: Configuration syntax (httpd.conf) Hooks: Code run at a certain point during request lifecycle Filters: Transformation of data: in and out Bucket brigades: Streams of Bits Handlers: Generation of data mod_proxy_fcgi is a handler, but it interacts with all of the above 24

Four main steps for a reverse proxy 1. Determine which backend to direct request to 2. Make/reuse connection to the backend 3. Process the request and deliver the backend response - fcgi_do_request() 4. Release the connection Steps 1, 2, and 4 use common mod_proxy code; Only step 3 is customized for FastCGI... 25

fcgi_do_request() phases Tell FastCGI we re starting a request... Send the CGI environment Calls dispatch() to handle request/response Pass along the request headers and body...wait... Read the response headers and body 26

Dealing with Brigades Apache 2.x deals with bucket brigades Brigades are collections of buckets Buckets are a chunk of data Handler - more specifically, dispatch() - creates bucket brigades and passes them down the filter chain (and also reads buckets for input too) 27

Passing along the request body On our connection to the backend, we ll do a loop around apr_poll() to wait until it s safe to write without blocking... rv = apr_poll(&pfd, 1, &n, timeout);... if (pfd.rtnevents & APR_POLLOUT) { Now, we ll read data from the request body via input filters: rv = ap_get_brigade(r->input_filters, ib, AP_MODE_READBYTES, APR_BLOCK_READ, sizeof(writebuf));...we ll format the ib brigade s buckets into a flat iovec structure... Pass the data to the FastCGI daemon using send_data(): rv = send_data(conn, vec, 2, &len, 0); 28

Processing the response Inside the same apr_poll() loop, we ll wait until we should read: if (pfd.rtnevents & APR_POLLIN) { Read the data from FastCGI using get_data helper: rv = get_data(conn, (char *) farray, &readbuflen); Translate the data into buckets: b = apr_bucket_transient_create(readbuf, readbuflen, c->bucket_alloc); APR_BRIGADE_INSERT_TAIL(ob, b); Pass the ob brigade onto the output filters so it can be sent to client: rv = ap_pass_brigade(r->output_filters, ob); Note how HTTP headers are handled! They must be set before first body byte is sent down the output filter chain or they will not be sent to the client. 29

Caching with mod_proxy Transparently cache from backend and store it on the local disk: CacheRoot /var/cache/apache/ CacheEnable disk / If the cache can not satisfy the request, it ll process the request normally - i.e. contact the reverse proxy. Use htcacheclean to control the size of the on-disk cache: htcacheclean -d15 -p/var/cache/apache -l250m (Every fifteen minutes, ensure the cache is no bigger than 250MB.) For more information about caching: http://httpd.apache.org/docs/2.2/caching.html 30

Recap mod_proxy supports a variety of protocols HTTP, HTTPS, AJP, FastCGI, FTP... Can act as a forward or reverse proxy 2.2+ features built-in load balancing Examples of how a backend provider is written using the mod_proxy framework 31

Painless Web Proxying with Apache mod_proxy Justin R. Erenkrantz University of California, Irvine and Google, Inc. http://www.erenkrantz.com/oscon/ justin@erenkrantz.com