Installation configuration of Lighttpd (web server software)

Source: Internet
Author: User
Tags gz file sapi valgrind
Lighttpd installation configuration (web server software)-Linux Enterprise Application-Linux server application information, the following is a detailed description. Lighttpd (http://lighttpd.net/) and apache are the same open source, compared with apache, although the function is not as good as apache, stability is not as good as apache, but, whether it is service static page, or service dynamic content (CGI, PHP), which is faster than apache. It is most appropriate for WEB servers such as ad banner.

This article describes how to install and configure lighttpd from the application perspective.

(1) Installation

Download the latest source code (.tar.gz) or rpm package from http://lighttpd.net/download. If you download the .tar.gz file, first./configure like other GNU software, and then make & make install. However, if you want to customize some functions, you have to take a good look at the output results of README, INSTALL, and./configure -- help after decompression. Here we will only talk about how to install it from the source code. For other installation methods, refer to http://trac.lighttpd.net/trac/wiki/tutorialinstallation.

$ Gzip-cd lighttpd-1.4.9.tar.gz | tar xf-
...
$ Lighttpd-1.4.9 cd
$./Configure -- help
'Configure 'configures lighttpd 1.4.9 to adapt to launch kinds of systems.

Usage:./configure [OPTION]... [VAR = VALUE]...

To assign environment variables (e.g., CC, CFLAGS...), specify them
VAR = VALUE. See below for descriptions of some of the useful variables.

Defaults for the options are specified in brackets.

Configuration:
...

Installation directories:
-- Prefix = PREFIX install architecture-independent files in PREFIX
[/Usr/local]
-- Exec-prefix = EPREFIX install architecture-dependent files in EPREFIX
[PREFIX]

By default, 'Make install' will install all the files in
'/Usr/local/bin','/usr/local/lib' etc. You can specify
An installation prefix other than '/usr/local 'using' -- prefix ',
For instance '-- prefix = $ home '.

For better control, use the options below.

Fine tuning of the installation directories:
...

Program names:
...

System types:
...

Optional Features:
-- Disable-FEATURE do not include FEATURE (same as -- enable-FEATURE = no)
-- Enable-FEATURE [= ARG] include FEATURE [ARG = yes]
-- Enable-maintainer-mode enable make rules and dependencies not useful
(And sometimes confusing) to the casual installer
-- Disable-dependency-tracking speeds up one-time build
-- Enable-dependency-tracking do not reject slow dependency extractors
-- Enable-static [= PKGS]
Build static libraries [default = no]
-- Enable-shared [= PKGS]
Build shared libraries [default = yes]
-- Enable-fast-install [= PKGS]
Optimize for fast installation [default = yes]
-- Disable-libtool-lock avoid locking (might break parallel builds)
-- Enable-lfs Turn on Large File System (default)
-- Disable-ipv6 disable IPv6 support

Optional Packages:
-- With-PACKAGE [= ARG] use PACKAGE [ARG = yes]
-- Without-PACKAGE do not use PACKAGE (same as -- with-PACKAGE = no)
-- With-gnu-ld assume the C compiler uses GNU ld [default = no]
-- With-pic try to use only PIC/non-PIC objects [default = use
Both]
-- With-tags [= TAGS]
Include additional configurations [automatic]
-- With-mysql [= PATH]
Include MySQL support. PATH is the path
'Mysql _ config'
-- With-ldap enable LDAP support
-- With-attr enable extended attribute support
-- With-valgrind enable internal support for valgrind
-- With-openssl [= DIR]
Include openssl support (default no)
-- With-openssl-nodes des = DIR
OpenSSL schemdes
-- With-openssl-libs = DIR OpenSSL libraries
-- With-kerberos5 use extensions os5 support with OpenSSL
-- With-pcre Enable pcre support (default yes)
-With-bzip2 Enable bzip2 support for mod_compress
-- With-fam/gamin for variable cing number of stat () CILS
-- With-webdav-props properties in mod_webdav
-- With-gdbm storage for mod_trigger_b4_dl
-- With-memcache memcached storage for mod_trigger_b4_dl
-- With-lua engine for mod_crf

Some influential environment variables:
...
As described above, you can use -- prefix to specify the installation path, which is installed under/usr/local by default. You can specify which features (INS) are enabled and which features (INS) are disabled ). Suppose we want to install lighttpd under/usr/local/lighttpd-1.4.9.

$./Configure -- prefix =/usr/local/lighttpd-1.4.9
$ Make
$ Make install
$ Cp doc/lighttpd. conf/usr/local/lighttpd-1.4.9/# copy the configuration file
$ Cd/usr/local/lighttpd-1.4.9
$ Vi lighttpd. conf # modify the configuration file
The configuration file is straightforward. You only need to change server.doc ument-root, server. errorlog, and accesslog. filename to your actual directory and file name.

$ Sbin/lighttpd-f lighttpd. conf # Start the lighttpd Service
$ Ps aux | grep lighttpd
Www 15403 0.0 0.9 2860 1148? S sbin/lighttpd-f
This completes the entire process from installation to startup, which is simple. From the output of the last line, we can see that lighttpd is a single-process service, which is different from apache (maybe it is not as stable as apache ).

(2) Integrate php and fastcgi

Take the php-4.3.11 as an example, when compiling PHP, you cannot specify the -- with-apxs option, compile the command line is roughly as follows:

$./Configure... -- enable-force-cgi-redirect -- enable-fastcgi
$ Make
$ Sapi/cgi/php-v
PHP 4.3.11 (cgi-fcgi) (built: Jan 30 2006 00:12:34)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
After make is complete, the php program under the command line is generated in the sapi/cli directory, and the php program under fastcgi is generated under sapi/cgi. If you execute php under sapi/cgi to display the version number, you will find cgi-fcgi instructions, which indicates that you have succeeded.

$ Mkdir/usr/local/lighttpd-1.4.9/fcgi
$ Cp sapi/cgi/php/usr/local/lighttpd-1.4.9/fcgi/
$ Vi/usr/local/lighttpd-1.4.9/lighttpd. conf
We create a sub-directory fcgi to save all the fast-cgi programs, and then copy php to this directory. Edit lighttpd. conf as follows:

...
Server. modules = (
...
"Mod_fastcgi ",
...)
...
Fastcgi. server = (". php" =>
("127.0.0.1" =>
(
"Socket" => "/tmp/fcgi_php.sock ",
"Bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/php"
)
)
)
Restart lighttpd. Lighttpd can communicate with fastcgi in two ways: through Unix socket communication, such as the above PHP startup, and through TCP/IP socket communication. Lighttpd supports fastcgi-based load balancing, but I have not tried it.

For more information about the fastcgi protocol specifications, see http://www.fastcgi.com/. The following is a configuration example of fastcgi:

Fastcgi. server = ("/fastcgi/adsim" =>
("127.0.0.1" =>
(
"Host" => "127.0.0.1 ",
"Port" = & gt; 4000,
"Bin-path" => "/usr/local/lighttpd-1.4.9/fcgi/adsim ",
"Check-local" => "disable"
)
)
Check-local must be set to disable; otherwise, the request fails because/fastcgi/adsim cannot be found.

(3) create a lighttpd Startup Script

Each time we start lighttpd, We need to specify the location of the configuration file. When we stop lighttpd, we need to first find the process number and then use kill to send the stop signal, which is a little too troublesome. Fortunately, lighttpd comes with a script program that can assist with these operations. It can be used only after slight modification, that is, the source code directory doc/rc. lighttpd and doc/rc. lighttpd. redhat, which is dedicated to RedHat Linux. The main changes are as follows:

...
If [-z "$ LIGHTTPD_CONF_PATH"]; then
LIGHTTPD_CONF_PATH = "/usr/local/The lighttpd-1.4.9/lighttpd. conf"
Fi
...
Lighttpd = "/usr/local/lighttpd-1.4.9/usr/sbin/lighttpd"
...
It is much easier to use this script to manage lighttpd.

(4) Lighttpd and OpenSSL

Lighttpd does not compile the ssl module by default. Therefore, you must explicitly specify -- with-openssl during compilation, and then generate the self-Signed server certificate or obtain it from the CA. The method for generating a self-signed certificate is as follows:

$ Openssl req-new-x509-keyout server. pem \
-Out server. pem-days 365-nodes
Lighttpd requires that certificates and private keys be stored in the same file. If they are separated, they must be merged:

$ Cat host. key host. crt> host. pem
Configure lighttpd. conf as follows:

Ssl. engine = "enable"
Ssl. pemfile = "server. pem"
You can set this for a virtual host, but because SSL works on the TCP layer, you cannot set a name-based virtual host, but you can only set a port-based virtual host. The following is a configuration example:

$ SERVER ["socket"] = "192.168.146.128: 443 "{
Ssl. engine = "enable"
Ssl. pemfile = "/usr/local/lighttpd/certs/server. pem"
Server.doc ument-root = "/home/www/wfs/www"
}
(5) configure the Directory List

Modify lighttpd. conf as follows:

Server. module = {
...
"Mod_dirlisting ",
...}

Dir-listing.activate = "enable"
(6) Configure CGI

To modify lighttpd. conf, first start mod_cgi, specify the cgi file extension in the static-file.exclude-extensions, and then associate it with the cgi. assign configuration command.

You can specify the path of the Resolution Program for CGI with an extension and the execution of a specific parsing program. For example:

Cgi. assign = (". pl" => "/usr/bin/perl ",
". Cgi" => "/usr/bin/perl ")
For CGI that can be executed without a specific parser by cutting the extension, you can specify that the parser is empty, for example:

Cgi. assign = (". cgi" => "")
CGI programs without an extension can only be accessed through a fixed path, for example:

Cgi. assgin = ("/cgi-bin/mycgi" => "/usr/local/cgi/mycgi)
(7) Configure Virtual Hosts

The Port-based virtual host configuration is described above. The name-based virtual host is also very simple. Modify lighttpd. conf, start the module mod_simple_vhost, and specify your VM information, such:

$ HTTP ["host"] = "news.example.org "{
Server.doc ument-root = "/var/www/servers/news2.example.org/pages /"
}
Lighttpd focuses on speed, while Apache focuses on stability and functions. You need to check the specific application for how to choose.


========================================================== =

Lighttpd 1.4.11 mod_ssi patch
Mod_ssi of lighttpd 1.4.11 does not support the following ssi syntax by default:

There are two files: test.shtmland header.shtml. the document title variable doc_title is set in test.shtml, and then include header.shtml. headers.shtml displays the webpage title based on the doc_title value. The specific content is as follows:

Test.shtml




Header.shtml



<! -- # Echo var = "doc_title" -->


Test


These two files work normally in apache, but cannot work normally in lighttpd 1.4.11. This problem occurs when the CNFUG.org service is transplanted to lighttpd, mod_ssi also does not support nesting # include. Later, according to The lighttpd 1.4.11 code, I wrote a small patch for mod_ssi to solve the above problem. The code is attached:

(Note: The nested # include code is provided by the marc@r4l.com's. Thank you marc! Code can also be obtained from here: http://matthew.cnfug.org/patch/mod_ssi.c.patch)

--- Mod_ssi.c Sun Apr 2 01:20:30 2006
++ Mod_ssi.c.modify Sun Apr 2 01:21:05 2006
@-36,6 + 36,9 @@
# Include
# Endif

+/* Determine if process finished */
+ Int h_finished = 0;
+
/* Init the plugin data */
INIT_FUNC (mod_ssi_init ){
Plugin_data * p;
@-57,7 + 60,7 @ FREE_FUNC (mod_ssi_free ){
UNUSED (srv );

If (! P) return HANDLER_GO_ON;
-
+
If (p-> config_storage ){
Size_t I;
For (I = 0; I <srv-> config_context-> used; I ++ ){
@-286, 6 + 289,37 @ static int build_ssi_cgi_vars (server * sr
Return 0;
}

+ URIHANDLER_FUNC (mod_ssi_physical_path ){
+ Plugin_data * p = p_d;
+ Size_t k;
+
+ If (con-> physical. path-> used = 0) return HANDLER_GO_ON;
+
+ Con-> loops_per_request ++;
+
+ Mod_ssi_patch_connection (srv, con, p );
+
+ For (k = 0; k <p-> conf. ssi_extension-> used; k ++ ){
+ Data_string * ds = (data_string *) p-> conf. ssi_extension-> data [k];
+
+ If (ds-> value-> used = 0) continue;
+
+ If (buffer_is_assist_right_len (con-> physical. path, ds-> value, ds-> value-> used-1 )){
+/* Handle ssi-request */
+
+ If (mod_ssi_handle_request (srv, con, p )){
+/* On error */
+ Con-> http_status = 500;
+}
+
+ Return HANDLER_FINISHED;
+}
+}
+
+/* Not found */
+ Return HANDLER_GO_ON;
+}
+
Static int process_ssi_stmt (server * srv, connection * con, plugin_data * p,
Const char ** l, size_t n ){
Size_t I, ssicmd = 0;
@-467,7 + 501,11 @ static int process_ssi_stmt (server * srv,
If (NULL! = (Ds = (data_string *) array_get_element (p-> ssi_cgi_env, var_val ))){
Buffer_copy_string_buffer (B, ds-> value );
} Else {
-Buffer_copy_string (B, "(none )");
+ If (NULL! = (Ds = (data_string *) array_get_element (p-> ssi_vars, var_val ))){
+ Buffer_copy_string_buffer (B, ds-> value );
+} Else {
+ Buffer_copy_string (B, "(none )");
+}
}

Break;
@-481,6 + 519,7 @ static int process_ssi_stmt (server * srv,
Const char * file_path = NULL, * pai_path = NULL;
Struct stat st;
Char * sl;
+ Buffer * tmp;

For (I = 2; I <n; I + = 2 ){
If (0 = strcmp (l , "File ")){
@-574,7 + 613,26 @ static int process_ssi_stmt (server * srv,
}
Break;
Case SSI_INCLUDE:
-Chunkqueue_append_file (con-> write_queue, p-> stat_fn, 0, st. st_size );
+/* Do recursive SSI expansion */
+/* Prevents infinite loop */
+ If (con-> loops_per_request> 25 | buffer_is_equal (con-> physical. path, p-> stat_fn )){
+ Buffer_copy_string (srv-> tmp_buf ," ");
+ Chunkqueue_append_buffer (con-> write_queue, srv-> tmp_buf );
+ Break;
+}
+
+ Tmp = buffer_init ();
+ Buffer_copy_string_buffer (tmp, con-> physical. path);/* save path of current document */
+ Buffer_copy_string_buffer (con-> physical. path, p-> stat_fn);/* next sub-document to parse */
+ If (mod_ssi_physical_path (srv, con, p )! = HANDLER_FINISHED ){
+/* The document was not processed, so write it as is */
+ Chunkqueue_append_file (con-> write_queue, con-> physical. path, 0, st. st_size );
+} Else {
+ H_finished = 1;
+}
+ Buffer_copy_string_buffer (con-> physical. path, tmp);/* restore saved path */
+ Buffer_free (tmp );
+
Break;
}
} Else {
@-897,7 + 955,11 @ static int mod_ssi_handle_request (server

/* Get a stream to the file */

-Array_reset (p-> ssi_vars );
+ If (h_finished = 1)
+ {
+ Array_reset (p-> ssi_vars );
+ H_finished = 0;
+}
Array_reset (p-> ssi_cgi_env );
Buffer_copy_string (p-> timefmt, "% a, % d % B % Y % H: % M: % S % Z ");
P-> sizefmt = 0;
@-1038,35 + 1100,6 @ static int mod_ssi_patch_connection (serv
}
# Undef PATCH

-URIHANDLER_FUNC (mod_ssi_physical_path ){
-Plugin_data * p = p_d;
-Size_t k;
-
-If (con-> physical. path-> used = 0) return HANDLER_GO_ON;
-
-Mod_ssi_patch_connection (srv, con, p );
-
-For (k = 0; k <p-> conf. ssi_extension-> used; k ++ ){
-Data_string * ds = (data_string *) p-> conf. ssi_extension-> data [k];
-
-If (ds-> value-> used = 0) continue;
-
-If (buffer_is_assist_right_len (con-> physical. path, ds-> value, ds-> value-> used-1 )){
-/* Handle ssi-request */
-
-If (mod_ssi_handle_request (srv, con, p )){
-/* On error */
-Con-> http_status = 500;
-}
-
-Return HANDLER_FINISHED;
-}
-}
-
-/* Not found */
-Return HANDLER_GO_ON;
-}
-
/* This function is called at dlopen () time and inits the callbacks */

Int mod_ssi_plugin_init (plugin * p ){
@-Listen 2, 3 + 1115,4 @ int mod_ssi_plugin_init (plugin * p ){

Return 0;
}
+

Usage:
$ Cd lighttpd-1.4.11/src
$ Patch
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.