Web Service acceleration through the kernel httpd

Source: Internet
Author: User
Article Title: web Service acceleration through the kernel httpd. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
I. Introduction
From linux2.4.13, an EXPERIMENTAL option-'[] Kernel httpd acceleration (EXPERIMENTAL)' appeared in Networking options. What is kHTTPd? It is a web server in a Linux environment. The difference between kHTTPd and other web servers is that it runs in the Linux kernel as part of the kernel (which can be considered as a device driver ).
  
KHTTPd only processes static (based on static files) web pages, and transmits all requests for non-static content to normal web servers running in the user space for processing, such as apache and Zeus, and the web servers running in the user space do not need to be modified.
  
The processing of http requests on static web pages is not a very complicated process, but it is a very important part of web Services, because at least most of the websites are static, there are also many static html files. A conventional web server is very easy to process http requests for static pages. It is just a simple operation to copy 'files to network. If these operations are completed in the kernel, they will become very efficient. For example, NFS servers that have completed similar functions are also running in the kernel.
  
By accelerating web request processing in the kernel, web servers such as apache can focus on processing those dynamic web requests.
  
Note: Apache refers to any web server.
  
Ii. Quick Start
1) Compile and load modules
2) If necessary, configure the module through/proc/sys/net/khttpd.
3) echo 1>/proc/sys/net/khttpd/start
  
Uninstall:
  
Echo 1>/proc/sys/net/khttpd/stop
Echo 1>/proc/sys/net/khttpd/unload
Rmmod khttpd
  
Iii. Configuration
1. Operation Mode
  
There are two recommended operation modes:
  
1) 'apache' is the master web server and kHTTPd is the auxiliary web server.
  
Clientport-> 80
Serverport-> 8080 (or whatever)
  
2) kHTTPd is the master web server and 'apache' is the auxiliary web server.
  
Clientport-> 8080 (or whatever)
Serverport-> 80
  
2. Configure kHTTPd
  
Before starting kHTTPd, you must configure it. This is done through the/proc file system, so you can implement automatic configuration in the script. Most parameters can only be set before kHTTPd is started.
  
You can configure the following parameters:
  
1) service request port listened by kHTTPd
2) The 'apache' listening port (in the 'localhost' Interface)
3) web document root directory (documentroot)
4) The string contained in the request for dynamic content (optional)
[Default includes "cgi-bin"]
  
The specified documentroot must be consistent with the documentroot of the web server running in the user space, because kHTTPd may redirect any requests to the web server of the user space for processing.
  
A typical script (the first operation mode)
  
#! /Bin/sh
Modprobe khttpd
Echo 80>/proc/sys/net/khttpd/clientport
Echo 8080>/proc/sys/net/khttpd/serverport
Echo/var/www>/proc/sys/net/khttpd/documentroot
Echo php3>/proc/sys/net/khttpd/dynamic
Echo shtml>/proc/sys/net/khttpd/dynamic
Echo 1>/proc/sys/net/khttpd/start
  
For the second operation mode, the typical script is as follows:
  
#! /Bin/sh
Modprobe khttpd
Echo 8080>/proc/sys/net/khttpd/clientport
Echo 80>/proc/sys/net/khttpd/serverport
Echo/var/www>/proc/sys/net/khttpd/documentroot
Echo php3>/proc/sys/net/khttpd/dynamic
Echo shtml>/proc/sys/net/khttpd/dynamic
Echo 1>/proc/sys/net/khttpd/start
  
In this case, you must first modify the Apache configuration:
  
Port 80
  
Change
  
Port 8080
  
3. Stop kHTTPd
  
To modify the configuration, stop kHTTPd:
  
# Echo 1>/proc/sys/net/khttpd/stop
  
If you want to uninstall the module and stop kHTTPd, run:
  
Echo 1>/proc/sys/net/khttpd/unload
  
If you feel that this process is too slow for you (the preceding Command needs to wait for the remote connection to be closed first), you can send an HUP signal to the server after it is stopped, this will cause the server thread to stop immediately.
  
Note: if these processes are not stopped, they will be restarted immediately.
  
Iv. Restrictions
The security mode of kHTTPd is very strict because web servers with user space can handle complicated situations:
  
KHTTPd processes the request only when the following conditions are met:
  
1) The URL does not contain '? '
2) The URL starts '/'.
3) the specified URL file exists.
4) The permission for this file is readable to all users (*)
5) the file is not a directory, not an executable file, and there is no sticky position (*)
6) The URL does not contain any illegal substrings, such as '..' and 'cgi-bin (*)
7) the mime type of the file is known (*)
  
* The condition marked later here is that requests that do not meet any of the above conditions configured through/proc/sys/net/khttpd will be forwarded to the web server of the user space for processing.
  
V. Parameters
The following parameters can be configured through/proc/sys/net/khttpd:
  
Default Value of variable name
  
Serverport 8080 kHTTPd listening service port
  
Clientport 80 listener port of the user space web Server
  
Threads 2 the number of server threads. For small web applications, each CPU corresponds to one thread. For large websites (active files are not stored in RAM ), the value should be the directory where each CPU corresponds to 2 documentroot/var/www web Content
  
Start 0 is set to 1 to start kHTTPd (this bit may be set to 0 automatically by 'Stop)
  
Stop 0 is set to 1 to stop kHTTPd (this bit may be set to 0 automatically by 'start)
  
Unload 0 is set to 1 to prepare to uninstall the kHTTPd Module
  
If sloppymime 0 is 1, the mime type so far is automatically set to text/html. If it is 0, files of unknown mimi type will be processed by the web server of the user space.
  
Minimum Limit required for perm_required S_IROTH (for the value, refer to 'man 2 stat ')
  
Perm_forbid dir + sticky + restrict mask prohibited by the file (for the value, refer to 'man 2 stat ')
  
Dynamic cgi-bin .. the child string contained in the dynamic content request URL
  
Maxconnect 1000 Max connections
  
6. More information
For more information about the kHTTPd architecture, refer to the http://www.fenrus.demon.nl
  
  

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.