⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 thttpd.8

📁 非常优秀的linux嵌入式http服务器
💻 8
📖 第 1 页 / 共 2 页
字号:
For comparison, a v.90 modem gives about 5000 B/s depending on compression,a double-B-channel ISDN line about 12800 B/s, and a T1 line is about150000 B/s.If you want to set a minimum rate as well, use number-number..PPExample:.nf  # throttle file for www.acme.com  **              2000-100000  # limit total web usage to 2/3 of our T1,                               # but never go below 2000 B/s  **.jpg|**.gif   50000   # limit images to 1/3 of our T1  **.mpg          20000   # and movies to even less  jef/**          20000   # jef's pages are too popular.fi.PPThrottling is implemented by checking each incoming URL filename against allof the patterns in the throttle file.The server accumulates statistics on how much bandwidth each patternhas accounted for recently (via a rolling average).If a URL matches a pattern that has been exceeding its specified limit,then the data returned is actually slowed down, withpauses between each block.If that's not possible (e.g. for CGI programs) or if the bandwidth has gottenway larger than the limit, then the server returns a special codesaying 'try again later'..PPThe minimum rates are implemented similarly.If too many people are trying to fetch something at the same time,throttling may slow down each connection so much that it's not reallyuseable.Furthermore, all those slow connections clog up the server, usingup file handles and connection slots.Setting a minimum rate says that past a certain point you should noteven bother - the server returns the 'try again later" code and theconnection isn't even started..PPThere is no provision for setting a maximum connections/second throttle,because throttling a request uses as much cpu as handling it, sothere would be no point.There is also no provision for throttling the number of simultaneousconnections on a per-URL basis.However you can control the overall number of connections for the wholeserver very simply, by setting the operating system's per-process filedescriptor limit before starting thttpd.Be sure to set the hard limit, not the soft limit..SH "MULTIHOMING".PPMultihoming means using one machine to serve multiple hostnames.For instance, if you're an internet provider and you want to letall of your customers have customized web addresses, you mighthave www.joe.acme.com, www.jane.acme.com, and your own www.acme.com,all running on the same physical hardware.This feature is also known as "virtual hosts".There are three steps to setting this up..PPOne, make DNS entries for all of the hostnames.The current way to do this, allowed by HTTP/1.1, is to use CNAME aliases,like so:.nf  www.acme.com IN A 192.100.66.1  www.joe.acme.com IN CNAME www.acme.com  www.jane.acme.com IN CNAME www.acme.com.fiHowever, this is incompatible with older HTTP/1.0 browsers.If you want to stay compatible, there's a different way - use A recordsinstead, each with a different IP address, like so:.nf  www.acme.com IN A 192.100.66.1  www.joe.acme.com IN A 192.100.66.200  www.jane.acme.com IN A 192.100.66.201.fiThis is bad because it uses extra IP addresses, a somewhat scarce resource.But if you want people with older browsers to be able to visit yoursites, you still have to do it this way..PPStep two.If you're using the modern CNAME method of multihoming, then you canskip this step.Otherwise, using the older multiple-IP-address method youmust set up IP aliases or multiple interfaces for the extra addresses.You can use ifconfig(8)'s alias command to tell the machine to answer toall of the different IP addresses.Example:.nf  ifconfig le0 www.acme.com  ifconfig le0 www.joe.acme.com alias  ifconfig le0 www.jane.acme.com alias.fiIf your OS's version of ifconfig doesn't have an alias command, you'reprobably out of luck (but see http://www.acme.com/software/thttpd/notes.html)..PPThird and last, you must set up thttpd to handle the multiple hosts.The easiest way is with the -v flag, or the ALWAYS_VHOST config.h option.This works with either CNAME multihosting or multiple-IP multihosting.What it does is send each incoming request to a subdirectory based on thehostname it's intended for.All you have to do in order to set things up is to create those subdirectoriesin the directory where thttpd will run.With the example above, you'd do like so:.nf  mkdir www.acme.com www.joe.acme.com www.jane.acme.com.fiIf you're using old-style multiple-IP multihosting, you should also createsymbolic links from the numeric addresses to the names, like so:.nf  ln -s www.acme.com 192.100.66.1  ln -s www.joe.acme.com 192.100.66.200  ln -s www.jane.acme.com 192.100.66.201.fiThis lets the older HTTP/1.0 browsers find the right subdirectory..PPThere's an optional alternate step three if you're using multiple-IPmultihosting: run a separate thttpd process for each hostname, usingthe -h flag to specify which one is which.This gives you more flexibility, since you can run each of these processesin separate directories, with different throttle files, etc.Example:.nf  thttpd -r -d /usr/www -h www.acme.com  thttpd -r -d /usr/www/joe -u joe -h www.joe.acme.com  thttpd -r -d /usr/www/jane -u jane -h www.jane.acme.com.fiBut remember, this multiple-process method does not work with CNAMEmultihosting - for that, you must use a single thttpd process withthe -v flag..SH "CUSTOM ERRORS".PPthttpd lets you define your own custom error pages for the variousHTTP errors.There's a separate file for each error number, all stored in onespecial directory.The directory name is "errors", at the top of the web directory tree.The error files should be named "errNNN.html", where NNN is the error number.So for example, to make a custom error page for the authentication failureerror, which is number 401, you would put your HTML into the file"errors/err401.html".If no custom error file is found for a given error number, then theusual built-in error page is generated..PPIf you're using the virtual hosts option, you can also have differentcustom error pages for each different virtual host.In this case you put another "errors" directory in the top of thatvirtual host's web tree.thttpd will look first in the virtual host errors directory, andthen in the server-wide errors directory, and if neither of thosehas an appropriate error file then it will generate the built-in error..SH "NON-LOCAL REFERERS".PPSometimes another site on the net will embed your image files in theirHTML files, which basically means they're stealing your bandwidth.You can prevent them from doing this by using non-local referer filtering.With this option, certain files can only be fetched via a local referer.The files have to be referenced by a local web page.If a web page on some other site references the files, that fetch willbe blocked.There are three config-file variables for this feature:.TP.B urlpatA wildcard pattern for the URLs that should require a local referer.This is typically just image files, sound files, and so on.For example:.nf  urlpat=**.jpg|**.gif|**.au|**.wav.fiFor most sites, that one setting is all you need to enable referer filtering..TP.B noemptyreferersBy default, requests with no referer at all, or a null referer, or areferer with no apparent hostname, are allowed.With this variable set, such requests are disallowed..TP.B localpatA wildcard pattern that specifies the local host or hosts.This is used to determine if the host in the referer is local or not.If not specified it defaults to the actual local hostname..SH SYMLINKS.PPthttpd is very picky about symbolic links.Before delivering any file, it first checks each element in the pathto see if it's a symbolic link, and expands them all out to get the finalactual filename.Along the way it checks for things like links with ".." that go abovethe server's directory, and absolute symlinks (ones that start with a /).These are prohibited as security holes, so the server returns anerror page for them.This means you can't set up your web directory with a bunch of symlinkspointing to individual users' home web directories.Instead you do it the other way around - the user web directories arereal subdirs of the main web directory, and in each user's homedir there's a symlink pointing to their actual web dir..PPThe CGI pattern is also affected - it gets matched against the fully-expandedfilename.  So, if you have a single CGI directory but then put a symboliclink in it pointing somewhere else, that won't work.  The CGI program will betreated as a regular file and returned to the client, instead of getting run.This could be confusing..SH PERMISSIONS.PPthttpd is also picky about file permissions.It wants data files (HTML, images) to be world readable.Readable by the group that the thttpd process runs as is not enough - thttpdchecks explicitly for the world-readable bit.This is so that no one ever gets surprised by a file that's not setworld-readable and yet somehow is readable by the HTTP server andtherefore the *whole* world..PPThe same logic applies to directories.As with the standard Unix "ls" program, thttpd will only let youlook at the contents of a directory if its read bit is on; butas with data files, this must be the world-read bit, not just thegroup-read bit..PPthttpd also wants the execute bit to be *off* for data files.A file that is marked executable but doesn't match the CGI patternmight be a script or program that got accidentally left in thewrong directory.Allowing people to fetch the contents of the file might be a security breach,so this is prohibited.Of course if an executable file *does* match the CGI pattern, then itjust gets run as a CGI..PPIn summary, data files should be mode 644 (rw-r--r--),directories should be 755 (rwxr-xr-x) if you want to allow indexing and711 (rwx--x--x) to disallow it, and CGI programs should be mode755 (rwxr-xr-x) or 711 (rwx--x--x)..SH LOGS.PPthttpd does all of its logging via syslog(3).The facility it uses is configurable.Aside from error messages, there are only a few log entry types of interest,all fairly similar to CERN Common Log Format:.nf  Aug  6 15:40:34 acme thttpd[583]: 165.113.207.103 - - "GET /file" 200 357  Aug  6 15:40:43 acme thttpd[583]: 165.113.207.103 - - "HEAD /file" 200 0  Aug  6 15:41:16 acme thttpd[583]: referer http://www.acme.com/ -> /dir  Aug  6 15:41:16 acme thttpd[583]: user-agent Mozilla/1.1N.fiThe package includes a script for translating these log entries infoCERN-compatible files.Note that thttpd does not translate numeric IP addresses into domain names.This is both to save time and as a minor security measure (the numericaddress is harder to spoof)..PPRelevant config.h option: LOG_FACILITY..PPIf you'd rather log directly to a file, you can use the -l command-lineflag.  But note that error messages still go to syslog..SH SIGNALS.PPthttpd handles a couple of signals, which you can send via thestandard Unix kill(1) command:.TP.B INT,TERMThese signals tell thttpd to shut down immediately.Any requests in progress get aborted..TP.B USR1This signal tells thttpd to shut down as soon as it's done servicingall current requests.In addition, the network socket it uses to accept new connections getsclosed immediately, which means a fresh thttpd can be started upimmediately..TP.B USR2This signal tells thttpd to generate the statistics syslog messagesimmediately, instead of waiting for the regular hourly update..TP.B HUPThis signal tells thttpd to close and re-open its (non-syslog) log file,for instance if you rotated the logs and want it to start using thenew one.This is a little tricky to set up correctly, for instance if you are usingchroot() then the log file must be within the chroot tree, but it'sdefinitely doable..SH "SEE ALSO"redirect(8), ssi(8), makeweb(1), htpasswd(1), syslogtocern(8), weblog_parse(1), http_get(1).SH THANKS.PPMany thanks to contributors, reviewers, testers:John LoVerso, Jordan Hayes, Chris Torek, Jim Thompson, Barton Schaffer,Geoff Adams, Dan Kegel, John Hascall, Bennett Todd, KIKUCHI Takahiro,Catalin Ionescu.Special thanks to Craig Leres for substantial debugging and development,and for not complaining about my coding style very much..SH AUTHORCopyright 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -