Introduction to the installation of LIGHTTPD and the use of basic modules
article Category: Ruby programming Keywords: lighttpd installation rewrite mod_proxy mod_secdownload
The front-end time for the system needs to get a lighttpd, mainly using FlowPlayer and lighttpd to build an online FLV streaming media playback capabilities. And LIGHTTPD also has a mod_flv_streaming module to support the streaming playback of FLV video, but I was simply using the function, not very in-depth, but the introduction is still possible.
The first is the installation of LIGHTTPD, lighttp installation needs pcre-7.6.tar.gz, mainly the regular-type analysis, installation package is as follows:
1.pcre-7.6.tar.gz (http://www.pcre.org/)
2.lighttpd-1.4.19.tar.gz (http://www.lighttpd.net/download/)
I. Installation of PCRE and LIGHTTPD 0 1//pcre Installation
0 2 #tar XF pcre-7.6.tar.gz
0 3 #cd pcre-7.6
0 4 #./configure
0 5 #make Clean
0 6 #make
0 7 #make Install
0 8
0 9//lighttpd Compile installation
#tar XF lighttpd-1.4.19.tar.gz
One #cd lighttpd-1.4.19
#./configure--prefix=/usr/local/lighttpd
#make Clean
#make
#make Install
16
Configuration files for//lighttpd, user groups, and user configurations
#mkdir/usr/local/lighttpd/etc
#cp doc/lighttpd.conf/usr/local/lighttpd/etc
#groupadd lighttpd
#useradd-G lighttpd lighttpd
22
Log file settings for//LIGHTTPD
#mkdir/usr/local/lighttpd/logs
#vi/etc/init.d/lighttpd
26 Modify LIGHTTPD_CONFIG=/ETC/SYSCONFIG/LIGHTTPD for/usr/local/lighttpd/etc/lighttpd.conf
27 Modify LIGHTTPD_BIN=/USR/SBIN/LIGHTTPD for/USR/LOCAL/LIGHTTPD/SBIN/LIGHTTPD
Second, the simple configuration of lighttpd and the main parameter description
#vi/usr/local/lighttpd/etc/lighttpd.conf
Server.modules to start the module as needed
Server.document-root to the root directory of your site (e.g./www)
Server.errorlog to the path of the error log (such as/usr/local/lighttpd/logs/error.log)
Accesslog.filename to access log path (such as/usr/local/lighttpd/logs/access.log)
Third, start lighttpd
#/usr/local/lighttpd/sbin/lighttpd-f/usr/local/lighttpd/etc/lighttpd.conf
Then we create a index.html under/www, enter Hello, and then visit the server to see the page, which indicates that the LIGHTTPD installation was successful.
LIGHTTPD's orders are as follows:
#/usr/local/lighttpd/sbin/lighttpd--help
-F <name> Specify the path to the configuration file
-M <name> Specify the loading directory for the module, default is/usr/local/lighttpd/lib
-P Displays the parsed profile information (run information) on the screen to specify the-f parameter
-T detects the correct line for the configuration file, specifying the-f parameter
-D setting lighttpd not background run, default is background run
-V Display LIGHTTPD version
-V Displays compile-time attribute information for LIGHTTPD
-H Display Help information, with--help
Four, lighttpd module configuration
LIGHTTPD follow the installation steps above, all of its modules have been installed in the/usr/local/lighttpd/lib directory, we set in the Server.modules module name and the Lib directory under the name of the module file can be consistent, such as Mod_ Secdownload.so is the representation of the Mod_secdownload module. We can add mod_secdownload to the Server.modules list to enable LIGHTTPD to support Mod_secdownload. You can also use this syntax to add modules: Server.modules + + ("Mod_secdownload")
1) rewrite module configuration
If you want to configure the rewrite module, write directly in the lighttpd.conf file:
Url.rewrite-once = (
^/show-([0-9]+)/. HTML "=>" $1.html,
"^/v/show-([0-9]+)/.html" => "$1.html"
)
If there are multiple, then use the Split open to write, as stated above. In addition to url.rewrite-repeat and other ways, see the documentation http://trac.lighttpd.net/trac/wiki/Docs%3AConfigurationOptions. Its basic regular style and Apache rewrite module is basically the same, but the writing form is not the same. For example, according to the above rewrite rules, we set up a file in the WWW directory: 123.html, and then visit: http://localhost:8080/show-123.html that can access to 123.html this file, and Direct access: HTTP ://localhost:8080/123.html is the same effect.
2) secdownload module configuration
Secdownload is a secure download module, the main principle is based on the timestamp to determine whether the request has timed out, if more than the specified time will not allow access to the specified resources, otherwise you can access. Its configuration in the lighttpd.conf file is as follows:
Secdownload.secret = "My-password"
Secdownload.document-root = "/home/my-download/"
Secdownload.uri-prefix = "/rs/dl/"
Secdownload.timeout = 60
First, the next lighttpd for the module URL requirements, if the use of LIGHTTPD secdownload module, then its request URL address must meet specific requirements can be, the URL format required by the following:
<uri-prefix>/<token>/<timestamp-in-hex>/<rel-path>
The URL address consists of four parts, each of which is described as follows:
1.<URI-PREFIX>: Secdownload.uri-prefix The specified prefix in the configuration file;
2.<token>: Is the MD5 encrypted string that is connected by the Secdownload.secret of the file specified in the configuration file plus the path to download (must begin with/start), and note that the example provided on the official website is PHP, where PHP's time () gets the 8 binary representation from 1970 to the current standard (in seconds), and if Java is used, it can be obtained by using the following code: 1 String timestamp = String.Format ("%08x", System.currenttimemillis ()/1000);
Because System.currenttimemillis () gets a millisecond, you should divide it by 1000. For example, I want to download the file File Store path is:/home/my-download/aa.txt. Note that the path prefix here is the value of the Secdownload.document-root in the configuration file, preferably by setting the Secdownload.document-root value outside the current lighttpd server.document-root directory, so you can Avoid direct downloads. Then the Java code for dynamically generating token for this file should be as follows: 1 String timestamp = String.Format ("%08x", System.currenttimemillis ()/1000);
2 String encoder = ENCRYPT.MD5 ("My-password" + "/aa.txt" + timestamp);
One of ENCRYPT.MD5 is my own MD5 encryption method, you can write one, note that the method of three parts I write separately, the first is that we set in the LIGHTTPD configuration file Secdownload.secret, the second is the name of the file we want to download (including the path), is The third part of the relative Secdownload.document-root path is the current timestamp we get. This allows us to dynamically generate a token that satisfies lighttpd requirements.
3.<timestamp-in-hex>: Is the time stamp we just generated, that is the timestamp above;
4.<rel-path>: This is the file we want to download, which is aa.txt.
The secdownload.timeout in the configuration file is used to verify how long the timestamp expires, and we set this here to be 1 minutes, or 60 seconds. This indicates that the link will be invalidated if no one clicks on the address from the 60s after we generate the download address. This will basically prevent files from being randomly downloaded.
3) Mod_proxy Agent module configuration
This module is primarily used to connect lighttpd and dynamic servers, such as Tomcat, and enter the following in the configuration file:
$HTTP ["url"] =~. jsp|. go|. Do|action "{
Proxy.balance = "Fair"
Proxy.server = ("" "=>" ("Host" => "127.0.0.1", "Port" => 8080), ("Host" => "127.0.0.1", "Port" => 18080) ))
}
Where the host field represents the configuration (IP and port) of the proxy server, and if there are multiple, you can configure the load server, which is configured with two. Proxy.loadblance used to do the load, the specific has not been studied, you can refer to the official document detailed understanding.
Here the main simple said LIGHTTPD installation deployment and simple module use, I hope you can communicate with each other ~ ~ ~