Download - Traffic Control in Apache
![Page 1: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/1.jpg)
Traffic Control in Apache
Jed Reynolds Blog.Bitratchet.com
Where in your web site do you need traffic control?
![Page 2: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/2.jpg)
Handling Traffic Efficiently
Right and Wrong Traffic Reduce redundant traffic Eliminate unwanted traffic Protect your dynamic content
Caching and tiered delivery
![Page 3: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/3.jpg)
Spectrum of Traffic Control
DNS
Content Delivery Network (CDN)
Proxies and load balancers
Application v static content servers Application server File system and disk
![Page 4: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/4.jpg)
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
![Page 5: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/5.jpg)
Redirects v Rewrites
Redirect sends a HTTP header, Location: Rewrites are server or application configurations
![Page 6: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/6.jpg)
Redirects with mod_alias
Redirect permanent ^/xml/ < uri http://xml.news.com/ < header
RedirectMatch permanent ^/xml/(.*)\.xml http://xml.news.com/$1.xml
![Page 7: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/7.jpg)
Rewrites with mod_alias
Alias /newspaper < uri /home/newspaper < disk
AliasMatch /(newspaper)/(*\.htm) /home/$1/today/$2
![Page 8: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/8.jpg)
Redirects with mod_rewrite
RewriteCond HTTP_HOST ^(.*)\.news.org$RewriteRule ^(.*)$ < uri http://%1.news.com/$1? < header [R=301,L] < rules
![Page 9: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/9.jpg)
Rewrites with mod_rewrite
RewriteRule /date/(.*) < uri /home/day/$1/index.htm < disk [L] < rule
![Page 10: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/10.jpg)
Avoid Combinations
Order of operations:
1) <Directory>2) <DirectoryMatch>3) <Files>,<FilesMatch> <<
rewrites
4) <Location>,<LocationMatch> << aliases
5) <VirtualHost> << repeat the above order inside VH’s after global scope
![Page 11: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/11.jpg)
Rewrite Scripts
Might be easier to write Possible performance or memory concerns What can you best maintain?
![Page 12: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/12.jpg)
Reducing Redundant Traffic with your Headers
Cache-Control: max-age=3600, must-revalidate
Expires: Fri, 30 Oct 1998 14:19:41 GMT
Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT
ETag: "3e86-410-3596fbbc"
Etags encourage freshest content Encourage client caching
![Page 13: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/13.jpg)
Extend Expires with mod_expires
<LocationMatch "/stuff/*">ExpiresActive onExpiresDefault "access plus 1 hour"</Location>
![Page 14: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/14.jpg)
Disable Etags
Mtime Inode File size
Header unset EtagFileETag none
![Page 15: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/15.jpg)
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
![Page 16: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/16.jpg)
Banning Traffic with <Directory>
<Directory /home/web>Order Allow,DenyDeny from 10.10.10.10</Directory>
![Page 17: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/17.jpg)
Banning Traffic with mod_rewrite
RewriteCond %{HTTP_USER_AGENT} ^NameOfBadRobot.*RewriteCond %{REMOTE_ADDR} ^123\.45\.67\.[8-9]$RewriteRule ^/news/.+ < uri - < placeholder [F] < rule
![Page 18: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/18.jpg)
Vastly More Traffic
Multiple servers, but where? Load balancer mod_proxy HA Proxy Reverse Proxy Caching Squid CDNs
![Page 19: Traffic Control in Apache](https://reader036.vdocument.in/reader036/viewer/2022062309/56813898550346895da0484a/html5/thumbnails/19.jpg)
Thank you
Jed Reynolds has been a programmer analyst since 1996 and enjoys bicycling and his Pentax K10D
blog.bitratchet.com @jed_reynolds [email protected]