Traffic Control in Apache Jed Reynolds Blog.Bitratchet.com Where in your web site do you need traffic control?
Handling Traffic Efficiently Right and Wrong Traffic Reduce redundant traffic Eliminate unwanted traffic Protect your dynamic content Caching and tiered delivery
Spectrum of Traffic Control DNS Content Delivery Network (CDN) Proxies and load balancers Application v static content servers Application server File system and disk
Right Traffic: URI Stability The URLs our site has might be precious The location on disk might be moved 20,000 sub directories 10,000 files Google and Sitemaps
Redirects v Rewrites Redirect sends a HTTP header, Location: Rewrites are server or application configurations
Redirects with mod_alias Redirect permanent ^/xml/ < uri < header RedirectMatch permanent ^/xml/(.*)\.xml
Rewrites with mod_alias Alias /newspaper < uri /home/newspaper < disk AliasMatch /(newspaper)/(*\.htm) /home/$1/today/$2
Redirects with mod_rewrite RewriteCond HTTP_HOST ^(.*)\.news.org$ RewriteRule ^(.*)$ < uri < header [R=301,L] < rules
Rewrites with mod_rewrite RewriteRule /date/(.*) < uri /home/day/$1/index.htm < disk [L] < rule
Avoid Combinations Order of operations: 1) 2) 3), << rewrites 4), << aliases 5) << repeat the above order inside VH’s after global scope
Rewrite Scripts Might be easier to write Possible performance or memory concerns What can you best maintain?
Reducing Redundant Traffic with your Headers Cache-Control: max-age=3600, must- revalidate Expires: Fri, 30 Oct :19:41 GMT Last-Modified: Mon, 29 Jun :28:12 GMT ETag: "3e fbbc" Etags encourage freshest content Encourage client caching
Extend Expires with mod_expires ExpiresActive on ExpiresDefault "access plus 1 hour"
Disable Etags Mtime Inode File size Header unset Etag FileETag none
Encourage 304 responses Apache is good with file content File content is fast Scripts should detect If-Modified-Since Scripts should send 304 Not Modified PHP Cache_Lite
Banning Traffic with Order Allow,Deny Deny from
Banning Traffic with mod_rewrite RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.* RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$ RewriteRule ^/news/.+ < uri - < placeholder [F] < rule
Vastly More Traffic Multiple servers, but where? Load balancer mod_proxy HA Proxy Reverse Proxy Caching Squid CDNs
Thank you Jed Reynolds has been a programmer analyst since 1996 and enjoys bicycling and his Pentax K10D