Monday, 22. May 2006, 11:54:39
这篇文章有时间真该翻译一下。
Apache tune-up tips:1.Upgrade Apache! The newest version contains several performance enhancements.
2.In httpd.conf, set "HostNameLookups off" which avoids doing a reverse DNS lookup on every visitor who hits your web site.
3.In httpd.conf, set "MaxClients 230" or higher for busier web sites. This allows more httpd daemons to run simultaneously and avoids clogging up the process queue. [Don't increase MaxClients to greater than your available RAM! Figure betwee 2 - 8 MB per client. 230 clients may require roughly 1 GB availableRAM].
4.Serve web graphics (such as GIF files) from another machine.
5.Make sure your web pages and CGI pages are browser cache friendly. See the "Caching Tutorial for Web Authors and Webmasters" at
http://www.pobox.com/~mnot/cache_docs/ [or here:
http://www.mnot.net/cache_docs/ or here: cache_docs/"]
6.Keep your Apache lean and mean. Compile Apache with as few modules as needed. Before compiling (before your run make), edit the /apache_1.x.x/src/Configuration file put a # in front of any AddModule lines you don't need.
7.If you don't need traffic logs (such as a site that only serves graphics) then use the TransferLog directive in httpd.conf to redirect log entries to /dev/null/
8.Unless you insist on using .htaccess files to control access to certain directories (there are other ways to do that), in access.conf (or httpd.conf in newer versions of Apache) in the section, set "AllowOverride None" so that Apache will not bother looking for an .htaccess file in each directory with each request.
9.DO NOT leave unnecessary background processes running. Removing extraneous background tasks not only improves performance but security as well. In the /etc/rc.d/rc3.d/ directory [on other systems, this may be different, for example, with Debian, it is /etc/rc2.d/. -D.], delete symlinks to processes you don't need to run. For a plain vanilla local disk web server in Linux, you should only need routed, network, inet, httpd, and local symlinks in your /etc/rc.d/rc3.d/ directory. Reboot the machine if you change the contents of that directory.
10.DO NOT serve web pages or write web traffic logs on a networked disk drive (ie. NFS networked disks) -- read and write to local disk drives only. NFS I/O operations incure huge overhead.
11.DO NOT run Apache (httpd) via the tcpd wrapper in /etc/inetd.conf. Apache can be started when the machine boots by either adding the startup command to your rc.local file or by placing the httpd startup script to your /etc/rc.d/rc3.d/ directory. If you want some mechanism to block requests by IP address then use the "deny from" directive in the Apache's conf files or in a .htacess file.
12.DO NOT leave X Windows running on your web server if you're not using it -- just be sure to Ctrl-Alt-Backspace to close the X session when you're done using it.
13.Avoid using SSI tags. [From
http://www.squid-cache.org/mail-archive/squid-users/199901/0080.html It might be worth noting that SSI pages can be made cacheable by using XBitHack full, with the appropriate x-bit settings. This doesn't specifically control the expiry date or cache-control headers, but Apache won't be generating anything that's actively harmful to cacheing in that respect; the proxy will apply its usual rules based on the last-modified header that's then generated based on the source file. AFAIK this _does_ work in practice with squid (whereas the "conventional" way of enabling SSI will result in the documents appearing to be uncacheable). ]
14.In CGI scripts:
o File I/O: Open as few files as possible. Be sure to explicetly close each opened file. Stop reading the file as soon as you found the data you need. Consider structuring data files into fixed-length fields and using read() function to skip ahead to just the part of the file you need to read.
o Shell Commands: Call shell commands via their full path: eg. use '/bin/date' instead of just `date` in a perl script.
o If your site is mostly CGI driven, by all means use mod_perl. See
http://perl.apache.org/ o Perl programmers should study "Effective Perl Programming" by Joseph N. Hall (an Addison Wesley book) and "The Perl Cookbook" by Tom Christiansen (an O'Reilly book) -- two good texts for optimizing perl code. For example, you can preallocate the memory for a hash that will contain 256 items like so: keys(%names) = 256;
o Avoid having more than 1000 files in your web page directory. Organize your web page files into subdirectories. The more files there are in a directory, the longer it takes to locate that file during a request.
15.Put as few graphics in your web pages as possible. Make sure each image is run through an image compressor.
16.Stress test your web site. Run Apache Benchmark program (called "ab") in Apache's /bin or /sbin directory. The ab program will simulate heavy traffic by running multiple simultaneous requests on any web page you want for as long as you want then measures the load and response times. Very useful for measuring the effects of your tuning efforts.
17.For best performance, unplug the network cable from your web server -- the load will drop down to zero almost instantly! ;-)
18.Set the 'noatime' mount option (in /etc/fstab) on your htdocs partition.
19.If you have a seperate partition for /tmp, you should set its mount options (in /etc/fstab) to nodev,noexec,nosuid. Doing so will add a bit more protection against hackers dropping a zombie bot in your /tmp and running it.
20.Consider using mod_gzip (or mod_deflate for Apache 2), or even pre-compressing static pages on disk.
21.Set KeepAliveTimeout to about 2 seconds. This offers the client enough time to request all files needed for a page load while ensuring that spare servers aren't unduly prevented from serving new client requests should there be a heavy load.
22.Disable ExtendedStatus unless you're actually debugging. Same goes for mod_info.
原文见:
http://users.encs.concordia.ca/~daniel/tips/apache_tuning.html