Linux Server adventure: Use lighttpd-Linux Enterprise Application-Linux server application information. The following is a detailed description. I. Why lighttpd?
Isn't apache acceptable?
When only static objects are supported, such as video clips and files,
Lighttpd is faster and more ideal
As for its comparison with apache, You can google it for many documents.
2. Where can I download lighttpd?
Http://www.lighttpd.net/download/
This is its official site.
3. How to install it?
1. Compile and install
./Configure -- prefix =/usr/local/lighttpd
Make
Make install
After configure is complete, an activated module and a list of unactivated modules are provided. You can check whether all required modules have been activated, "mod_rewrite" must be included in the enable module; otherwise, re-check whether the pcre is installed.
If your Linux is RedHat/CentOS, then:
Cp doc/rc. lighttpd. redhat/etc/init. d/lighttpd
If your Linux is SuSE, then:
Cp doc/rc. lighttpd/etc/init. d/lighttpd
For other Linux versions, you can modify them by referring to the file content.
Modify/etc/init. d/lighttpd and
LIGHTTPD_BIN =/usr/sbin/lighttpd
Change
LIGHTTPD_BIN =/usr/local/lighttpd/sbin/lighttpd
This script is used to control the startup, shutdown, and restart of lighttpd:
/Etc/init. d/lighttpd start
/Etc/init. d/lighttpd stop
/Etc/init. d/lighttpd restart
3. Configuration
Modify/etc/lighttpd. conf
1) server. modules
Uncomment the module that needs to be used. mod_rewrite, mod_access, mod_fastcgi, mod_simple_vhost, mod_cgi, mod_compress, and mod_accesslog are generally used.
Let's release mod_rewrite"
"Mod_compress ",
22.16server.doc ument-root, server. error-log, accesslog. filename need to specify the corresponding directory
Server.doc ument-root = "/www/scc/html /"
Mkdir/usr/local/lighttpd/logs
Chmod 777/usr/local/lighttpd/logs/
Touch/usr/local/lighttpd/logs/error. log
Chmod 777/usr/local/lighttpd/logs/error. log
3) What permissions are used to run lighttpd?
Server. username = "nobody"
Server. groupname = "nobody"
From the security perspective, it is not recommended to run the web server with the root permission. You can specify the common user permissions on your own.
Some static resource types can be specified for transmission in compression mode to save bandwidth,
For a large number of AJAX applications, the page loading speed can be greatly improved.
1. Maximum number of connections
The default value is 1024.
Modify server. max-fds. We recommend that you use 2048 for high-traffic websites.
Because lighttpd is based on threads, while apache (MPM-prefork) is based on sub-processes,
Therefore, you do not need to set startservers, maxclients, and so on for apache.
2 stat () Cache
The overhead of system calls such as stat () is also quite obvious.
Cache saves time and environment switching times (context switches)
In a word, add lighttpd. conf
Server. stat-cache-engine = "fam"
Lighttpd also provides simple (stat () cached within 1 second) and disabled options.
I believe no one will choose disabled.
HTTP Keep-Alive)
Generally, the number of files that a system can open is limited (file descriptor restrictions)
The persistent connection occupies the file descriptor, which has no significance for non-concurrent access.
(The number of file descriptors is related to many reasons, such as the number of log files and the number of concurrent operations)
This is the default value of lighttpd in keep-alive.
Server. max-keep-alive-requests = 128
Server. max-keep-alive-idle = 30
In other words, lighttpd can support up to 30 seconds of persistent connections at the same time, and each connection can request a maximum of 128 files.
However, this default value is not suitable for non-concurrent scenarios.
Decrease in lighttpd. conf
Server. max-keep-alive-requests
Server. max-keep-alive-idle
Two values can reduce this phenomenon.
You can even disable lighttpd keep-alive.
Server. max-keep-alive-requests = 0
4. Event Processing
For linux kernel 2.6, there is nothing to say
Adding this sentence to lighttpd. conf is sufficient.
Server. event-handler = "linux-sysepoll"
In addition,
Use linux-rtsig in linux 2.4
Freebsd uses freebsd-kqueue
Use poll for unix
5. network processing
Lighttpd uses sendfile () in a large amount for efficient system calls.
Reduces the distance from the application to the network card.
(It also reduces the cpu usage of lighttpd, which is transferred to the kernel)
You can set different parameters based on the platform.
Server. network-backend = "linux-sendfile"
(Linux)
Freebsd: freebsd-sendfile
Unix: writev
If you are interested, you can also see the implementation of lighttpd on async io (aio), only lighttpd 1.5
(Linux-aio-sendfile, posix-aio, gthread-aio)
In addition, core network parameters need to be modified as appropriate,
You do not need to describe it in detail here.
5. Start
6. Configure logs
Logrotate & cronolog
Logrotate is very rough. It directly chopped the process and moved the log.
Cronolog is a good method.
Lighttpd usage:
Accesslog. filename = "|/usr/sbin/cronolog/var/log/lighttpd/% Y/% m/% d/access_XXXX.log"
7. Install pcre
Where to download?
Http://www.pcre.org/
Wget ftp://ftp.csx.cam.ac.uk/pub/soft... re/pcre-7.4.tar.bz2
Installation Process:
./Configure
Make clean
Make
Make install
8. Supports fam.
Gamin has installed this package by default.
Yum install gamin-devel
In addition, you need to add:
./Configure -- prefix =/usr/local/lighttpd -- with-fam
9. Test the lighttpd startup:
/Usr/local/lighttpd/sbin/lighttpd-f/usr/local/lighttpd/etc/lighttpd. conf
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.