Project

General

Profile

FrequentlyAskedQuestions » History » Revision 74

Revision 73 (darix, 2015-08-11 12:06) → Revision 74/83 (gstrauss, 2020-05-22 15:06)

h1. FAQs 

 h2. Where to get help? 


 IRC: "freenode":http://www.freenode.net/,    channel "#lighttpd":irc://irc.freenode.net/lighttpd 

 Mailing list: [[WikiStart#Community]], [[Mailinglists]] http://news.gmane.org/gmane.comp.web.lighttpd. 

 h2. General 

 h3. How do I bind to more than one address? 

 Use server.bind and server.port to bind to the first port and then the $SERVER["socket"] conditional to bind to the rest (it will 'magically' bind to the specified socket). 

 Example that exposes /server-status to an internal IP only (note that it's perfectly valid to leave the body of the conditional empty): 

 <pre> 

 server.port = 80 
 server.bind = "192.0.2.1" 

 $SERVER["socket"] == "192.168.2.100:80" { 
    status.status-url = "/server-status" 
 } 

 $SERVER["socket"] == "/path/to/unix_domain_socket:1" { } 
 </pre> 


 This can also be combined with [[lighttpd:Docs_SSL|SSL]]. 


 h3. Do you support .htaccess files? 

 No. lighttpd's Lightys design does not permit implementing this functionality as config files are loaded at startup time and .htaccess would be needed to be parsed at request time. 
 Also scanning all the directories in the request path for those files can cause significant slowdown especially because lighty is single process and single threaded. 
 Furthermore, Furhtermore, .htaccess files are Apache config files. We would need to write a parser and it might not even be possible to map all functionality to lighty logic. 

 h3. What kind of environment does server.error-handler-404 set up? 


 The environment (which is relevant when using CGI or FastCGI) is quite normal, but observe the following: 

 * The REQUEST_URI is the *original* original request, and has nothing to do with where the redirect points to. 
 * The rest of the CGI environment is based off the @server.error-handler-404@ target.  
 * QUERY_STRING is _not_ set from the original request, set, so you have to parse the REQUEST_URI yourself to get it. 
 * PATH_INFO, similarly, is not set from the original request. Likewise, PATH_INFO isn't set. 
 * SCRIPT_NAME is set according to the @server.error-handler-404@ target, handler, not according to the original REQUEST_URI. 
 * REDIRECT_STATUS is the error status of the original request (e.g. 404 or 403) for which @server.error-handler-404@ is being called. URI. 


 h3. Why is server.error-handler-404 serving 200 instead of 404? 


 Quote from Jan: 

 <pre> 

 Yes. As we handle the error we generate a something new. If you just 
 want to send a custom-404 errorpage, there is server.errorfile-prefix 
 </pre> 

 For further information read the server.errorfile-prefix entry [[lighttpd:Docs_Configuration|in configuration info]]. 

 If your target handler for @server.error-handler-404@ checks REDIRECT_STATUS, it can choose to return that status instead of 200. 

 For full control over all HTTP error status codes, see "server.error-handler":https://redmine.lighttpd.net/projects/lighttpd/repository/14/revisions/dbdab5dbc9b98df9c40f11e0fc6a6ce49bfea804 


 h3. How do I protect a directory with a password? 


 Look in the doc/authentication.txt 

 If you're converting from Apache, htpasswd authentication backend is what you're looking for. 

 See also [[HowToAuthenticationFromMultipleFiles]] 


 h3. Can I use Apache Modules with lighttpd? 


 No, Apache modules are not compatible with lighttpd. 


 h3. Can I use SVN over WebDAV with lighttpd? 


 No, use Apache. If you would like, you can proxy requests to Apache through lighttpd. 


 h3. What is lighttpd's equivalent to Apache's "Options +!MultiViews"? 


 See [[MigratingFromApache#MultiViews]] 


 h3. Why do I still get a 403 status, even though the permissions on my doc root directory and its contents are set to 755? 

 Nine times out of ten (in IRC support), you have forgotten to check the permissions on one of the parent directories. Double check each directory in your path to insure the lighttpd user can access the nested doc root. selinux and alike might also play tricks on you :) 

 h3. Why do some random static files take ~1s in response time? 

 This has been experienced on Debian Lenny, and default libglib 2.16.6 packages. Upgrading package libglib2.0-0 to 2.22bpo found in backports.org resolved this issue. 


 h2. FastCGI 



 h3. Where is the spawn-php program/script available from? it's mentioned in docs but not available in the distributed package (1.3.7) 


 If you install lighttpd (http://lighttpd.net/download/INSTALL), the spawn-fcgi binary is installed automatically (on versions < 1.4.23). 

 Its now a seperate package living at: http://redmine.lighttpd.net/projects/spawn-fcgi 


 h3. Is there an su-exec wrapper available? 


 Not officially, but Sune Foldager coded one especially for lighttpd which you can grab "here":http://cgit.stbuehler.de/gitosis/execwrap/. It's very easy to use, but has not yet been extensively tested so a little caution is advised. On the other hand, the source is very small so it's easy to get a security overview. Instructions and usage examples (with lighttpd) are in the "README":http://cyanite.org/projects/execwrap/READ_ME. 

 

 h3. How do I exclude a certain directory from FastCGI? 



 <pre> 

 $HTTP["url"] !~ "^/no-fcgi/" { 
 # to exclude multiple directories: $HTTP["url"] !~ "^/(?:no-fcgi1|foo/no-fcgi2|bar)/" { 
    fastcgi.server = ( "/" => ... ) 
 } 
 </pre> 


 You *can* also use server.error-handler-404 to redirect all non-existent files to FastCGI (see LighttpdOnRails for an example), but you should not. It is known to have unexpected side effects and is more a hack than a real solution. Use mod_magnet whenever you need such changes, darix provides very good scripts (which should fit a lot of web apps) at his "website":http://nordisch.org/ 

 "website":http://nordisch.org./. 

 h3. I get the error "No input file specified" when trying to use PHP 

 Sadly, this error message can mean a lot of things. A common explanation attempt: PHP is unable to locate or open the file which it is supposed to parse. This can have a lot of reasons: 
 * You forgot to add '''cgi.fix_pathinfo=1 to your php.ini''' file 
     See the comments in the "PHP docs":http://www.php.net/manual/de/security.cgi-bin.php. The issue here is that the environment variable @SCRIPT_FILENAME@ is not being passed to PHP. 
 * Make sure you did not set *doc_root or userdir in php.ini*, or if you have set it, make sure it has the correct value (doc_root should match lighttpd's server.document-root option in this case) 
 * If open_basedir is set, make sure the requested file is below one of the directories which is specified there. In the past PHP parsed files which were not inside open_basedir as well, but this security problem was fixed (in php-5.2.3 or so). 
 * If you are running PHP with different permissions than lighttpd (spawn-fcgi with -u/-g, execwrap, suexec, ...), check that PHP can really read the file 

 If you are unable to find / fix the problem, you can use [[HowToReportABug#strace|strace]] to see if it is a (OS-related) permission problem (look out for stat*(...YOURFILE...) = RETURNCODE). It might help to set @max-procs@ to 1 and @PHP_FCGI_CHILDREN@ as well (see [[lighttpd:Docs_ModFastCGI|fastcgi docs]]) in that case, so that you can easily attach strace to the correct php-cgi process. 

 h3. How many php CGI processes will lighttpd spawn? 

 lighttpd has three configuration options that control how many php-cgi processes will run: 

  * @PHP_FCGI_CHILDREN@ (defaults to 1) 
  * @max-procs@ (default 4) 
  * @min-procs@ is completely ignored in recent lighttpd releases (there is no adaptive spawning anymore) 

 When lighttpd starts, it will launch max-procs parent php processes.    Each parent process then pre-forks PHP_FCGI_CHILDREN child processes.    For example, if max-procs are 4 and PHP_FCGI_CHILDREN is 16, lighttpd will start max-procs x ( PHP_FCGI_CHILDREN + 1). In our case: 4 * ( 16 + 1 ) = 68 (4 watcher processes which do not handle requests, 64 real php backends which serve requests). 

 If you are using an opcode cache such as eAccelerator, XCache or similar it's advisable to keep max-procs at a very low number (1 is perfectly fine) and raise PHP_FCGI_CHILDREN instead. Those opcode caches will create a separate memory space for each parent process, otherwise, which is not what one would call "efficient memory usage" in that case..    If you leave max-procs at 4, you'll end up with four separate opcode memory cache segments. 

 Note that setting PHP_FCGI_MAX_REQUESTS is recommended to avoid possible memory leak side-effects. 

 h3. What does %1/$1 mean? 

 It's just "lighty speak" for [http://www.regular-expressions.info/brackets.html backreferences]]. (See doc/rewrite.txt and doc/redirect.txt.) 

 %n is used to denote a backreference on the conditional, and $n is used to backreference on the redirect/rewrite regex. If you need to learn about regexen, "Regular-Expressions.info":http://www.regular-expressions.info/ is as good a place to start as any. 


 h3. What does "(server.c.XXX) connection closed - write-request-timeout: YY" in my error log mean? 


 This error means that a client connection has timed out and lighttpd has closed the connection. This error on its own is not something to worry about as it can occur regularly during the course of normal site operation.    The default timeout is 360 seconds and can be set using "server.max-write-idle":http://lighttpd.net/documentation/configuration.html. There´s a silence-option for this now. 


 h3. Why: 'unexpected end-of-file (perhaps the fastcgi process died)'? or random '500 - Internal Server Error' 

 If you are using FastCGI with PHP then this may be caused by using PHP extensions that are unstable.    For example the following configuration caused my lighttpd install to respond sometimes to identical queries with '500 - Internal Server Error' and sometimes with the page requested.    The issue was fixed by removing the APD 'extension' line in the relevant PHP    configuration file. 

 <pre> 

 PHP 5.1.6-pl6-gentoo (cgi-cgi) (built: Feb    8 2007 11:14:58) 
 Zend Engine v2.1.0, Copyright (c) 1998-2006 Zend Technologies 
   with Advanced PHP Debugger (PAD) v0.9, , by George Schlossnagle 
 </pre> 


 Note that in php5.2.5 there is also this bug 

 http://bugs.php.net/bug.php?id=43295  

 which has similar symptoms, symtoms, but needs a patch to PHP 

 http://cvs.php.net/viewvc.cgi/php-src/main/SAPI.c?r1=1.202.2.7.2.15&r2=1.202.2.7.2.16&pathrev=PHP_5_2&diff_format=u  

 or wait until 5.2.6 since the patch is committed to php's CVS by dimitry. 



 h2. SSL 


 h3. Microsoft Internet Explorer reports "bad data from server" when surfing an SSL-enabled Lighttpd site 

 This is most likely because of some known bugs in the implementation of SSL in some old versions of MSIE.  

 The current solution (equivalent of using SetEnvIf in Apache) is using the following configuration snippet: 

 <pre> 

 $HTTP["useragent"] =~ "MSIE" { 
   server.max-keep-alive-requests = 0 
 } 
 </pre> 

 (from http://article.gmane.org/gmane.comp.web.lighttpd/3447) 



 h2. MacOSX 

 h3. Lighttpd crashes when using server.event-handler="poll" in MacOSX 
 Configure lighttpd to use kqueue as the event-handler: 


 <pre> 

   server.event-handler = "freebsd-kqueue" 
 </pre> 

  
 See also: [[server_event-handlerDetails|server.event-handler option]]