One of the httpd articles of CentOS6.5 web-http agreement

Source: Internet
Author: User

Web services are important in network communication, and what we're going to show here is the heavy-http protocol in Web services.

Under CentOS6.5, the Implementation tool for the HTTP protocol is called HTTPD, and we can use commands to view the current version of HTTPD and whether the HTTPD service is installed on this machine.

For example:

[Email protected] conf]# rpm-q httpd
Httpd-2.2.15-29.el6.centos.x86_64

This is the version of HTTPD 2.2.15. This version of HTTPD has a number of features, which are presented in the following example: Suppose our environment: a VMware Virtual host serves as a server-side Web service, and our client simulations use Win7

Then start between httpd, first say httpd has a master configuration file, defined httpd many new features. Due to our httpd2.2 version, two working modes are defined by default, one is Prefork and the other is worker.

We can see what files are generated by the HTTPD program through RPM–QL httpd.

[Email protected] conf]# RPM-QL httpd

......

/USR/SBIN/HTTPD (actually it's prefork)
/usr/sbin/httpd.event
/usr/sbin/httpd.worker

Since HTTPD has a working mode, you must know which mode it works in, it is prefork mode by default, and it has a worker mode. Let's take a look at each of the two features in the config file:

(The server pre-generates something like "process pool (Server-pool)" Before responding to a client request, generating many sub-processes, the client responds, and we respond from the pool tone process)

For Prefork mode: In this working mode, the server's main process will fork itself to produce multiple sub-processes, each of which responds to a customer request.

<ifmodule prefork.c>
When the Startservers 8 service is turned on, 8 idle processes are generated
Minspareservers 5 Minimum number of idle processes
Maxspareservers 20 Maximum number of idle processes
Serverlimit 256 The maximum number of processes requested

MaxClients 256 maximum number of client requests allowed by the server at the same time
Maxrequestsperchild 4000 maximum number of requests per child process

</IfModule>

For this worker pattern: In worker mode, each child process generates many threads, and each thread requests a client request.

<ifmodule worker.c>
Startservers 4 Server restarts with 4 idle processes waiting for a client connection
MaxClients 300 indicates the maximum number of concurrent user requests allowed at the same time
Minsparethreads 25 minimum number of idle threads
Maxsparethreads 75 Maximum number of idle threads
Threadsperchild 25 Number of threads each child process can open

Maxrequestsperchild 0 The maximum number of requests per child process to handle

So we have a general understanding, we do the experimental experiment under the two modes of work.

Implementation: By renaming the configuration file method to open the working mode, such as:

[Email protected] sbin]# ll/usr/sbin/httpd*
-rwxr-xr-x. 1 root root 354816 2013/usr/sbin/httpd
-rwxr-xr-x. 1 root root 368168 2013/usr/sbin/httpd.event
-rwxr-xr-x. 1 root root 367240 2013/usr/sbin/httpd.worker

Now we turn on the HTTPD service to see the number of idle processes:

[[Email protected] sbin]# PS aux | grep "httpd*"
Root 2843 0.0 1.6 241748 8260? Ss 11:04 0:00/usr/sbin/httpd
Apache 2846 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2847 0.0 0.9 241748 4776? S 11:04 0:00/usr/sbin/httpd
Apache 2848 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2849 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2850 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2851 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2852 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd
Apache 2853 0.0 0.9 241748 4772? S 11:04 0:00/usr/sbin/httpd

Root 3550 0.0 0.1 103252 828 pts/1 s+ 13:41 0:00 grep httpd*

The process for marking the red italic is exactly 8, and the default number of 8 idle processes is turned on for the corresponding profile.

Now we switch to Httpd.worker working mode:

First look at the following:

[Email protected] sbin]#!ll
ll/usr/sbin/httpd*
-rwxr-xr-x. 1 root root 354816 2013/usr/sbin/httpd
-rwxr-xr-x. 1 root root 368168 2013/usr/sbin/httpd.event
-rwxr-xr-x. 1 root root 367240 2013/usr/sbin/httpd.worker

---------------------------------------------------------------------------------------------

Rename file again

[Email protected] sbin]# mv/usr/sbin/httpd/usr/sbin/httpd.prefork
[Email protected] sbin]# MV/USR/SBIN/HTTPD.EVENT/USR/SBIN/HTTPD

Restart Service

[Email protected] sbin]# service httpd restart
stopping httpd: [OK]
Starting httpd: [OK]

Now we look at the number of idle processes:

[Email protected] sbin]#!ps
PS aux | grep "httpd*"
Root 3578 0.0 0.8 184488 4032? Ss 13:46 0:00/usr/sbin/httpd
Apache 3581 0.0 0.6 528748 3276? Sl 13:46 0:00/usr/sbin/httpd
Apache 3582 0.0 0.6 528748 3284? Sl 13:46 0:00/usr/sbin/httpd
Apache 3583 0.0 0.6 528748 3280? Sl 13:46 0:00/usr/sbin/httpd
Root 3668 0.0 0.1 103252 832 pts/1 s+ 13:48 0:00 grep httpd*

Add the root user to the 80 port open listening socket This idle process, exactly 4.

Because the HTTPD service requires socket-based file communication, IP and port formats are required, so the master configuration file also defines the concept of the port, so that it does not pass the recognized 80 port.

Listen 80
Listen 38080

I've defined a 38080 port to use for Web services, so let's look at the actual effect:

[Email protected] sbin]# SS-TNLP | grep "httpd*"
LISTEN 0 128::::::* Users: (("httpd", 3805,4), ("httpd", 3808,4), ("httpd", 3809,4), ("httpd", 3810,4), ("httpd", 3811,4), (httpd), 3812,4), ("httpd", 3813,4), ("httpd", 3814,4), ("httpd", 3815,4))
LISTEN 0 128::: 38080:::* Users: (("httpd", 3805,6), ("httpd", 3808,6), ("httpd", 3809,6), ("httpd", 3810,6), ("httpd", 3811,6), (httpd), 3812,6), ("httpd", 3813,6), ("httpd", 3814,6), ("httpd", 3815,6))

Since our httpd is highly modular, it can be loaded dynamically and is very useful! For example: We want to disable the function of a module, take auth_digest as an example, we will ban it.

LoadModule Auth_basic_module modules/mod_auth_basic.so

#LoadModule Auth_digest_module modules/mod_auth_digest.so

Save and view directly

[Email protected] ~]# httpd-d dump_modules | grep "Digest"
Syntax OK
[[email protected] ~]# echo $?
1

Note that the digest module is blocked by us, it can be successfully commented out directly, do not need to restart the service or reread the configuration file.

In fact, our Web service is best not to open the service as root directly, so the configuration file defines the user to start the HTTP service, as follows

User Apache
Group Apache

Corresponding to the host, look!

Apache 3808 0.0 1.1 241880 5564? S-0:00/USR/SBIN/HTTPD
Apache 3809 0.0 1.1 241880 5564? S-0:00/USR/SBIN/HTTPD
Apache 3810 0.0 1.1 241748 5444? S-0:00/USR/SBIN/HTTPD
Apache 3811 0.0 1.1 241748 5444? S-0:00/USR/SBIN/HTTPD
Apache 3812 0.0 1.1 241748 5444? S-0:00/USR/SBIN/HTTPD
Apache 3813 0.0 1.1 241880 5564? S-0:00/USR/SBIN/HTTPD
Apache 3814 0.0 1.1 241748 5440? S-0:00/USR/SBIN/HTTPD
Apache 3815 0.0 1.1 241748 5444? S-0:00/USR/SBIN/HTTPD

Let's talk again about where the homepage address of the Web page is, because our environment CentOS6.5 this Linux system host to provide httpd services, so the home page is likely to define a directory under Linux as the portal for Web services, in the configuration file to write

Documentroot/var/www/html

It defines the "portal" of the Web service, assuming it has a 1.html file under the Linux host, and if it is edited, it will be accessible to 1.html with our client (Win7), right, let's try:

[Email protected] ~]# ll/var/www/html/1.html
-rw-r--r--1 root root 9 14:22/var/www/html/1.html

[Email protected] ~]# cat/var/www/html/1.html
Hellooooooooooooo

Ask our customers to request this page

650) this.width=650; "Style=" border-right-0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px "title=" 1 "border=" 0 "alt=" 1 "src=" http://img1.51cto.com/attachment/201408/10/6249823_ 1407644126bzrh.jpg "width=" 244 "height="/>

That's right!

First, the httpd directory usually has a index.html, this page is usually defined by the main page, if not, the server will become a similar "download" page, let us see

[Email protected] ~]# ll/var/www/html/
1.html c6/ct6.cfg hello.html hi.html ks.cfg repodata/test.html zabbix/

There is no index.html, is it. Let our client access it try:

650) this.width=650; "Style=" border-right-0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px "title=" 2 "border=" 0 "alt=" 2 "src=" http://img1.51cto.com/attachment/201408/10/6249823_ 1407644130was6.jpg "width=" 244 "height=" 236 "/>

What is this for?

In fact, this is the configuration file defined by the access mechanism, in the configuration file has a set of default DocumentRoot page parameters, note in the configuration file here,

<directory "/var/www/html" >
Options Indexes FollowSymLinks

Mainly see indexes This parameter, if you take it will show that, there is a download list, let you pick the download, this is not a potential huge leak, usually we can remove this item, if removed, as if, as if to look like, such as in front of indexes plus a-character, This in fact ensures a great degree of security. In fact, our configuration file is written here.

# same purpose, but it's much slower.
401 #
402 DirectoryIndex index.html Index.html.var

Find index.html from here as homepage

<directory "/var/www/html" >
Options-indexes FollowSymLinks

Save and reread the configuration file.

650) this.width=650; "Style=" border-right-0px; border-top-width:0px; border-bottom-width:0px; border-left-width:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201408/10/ 6249823_14076441324zjs.png "width=" 244 "height=" 119 "/> Haha, is not very magical!

And what does this followsymlinks mean, let's give an example:

Create a soft link to 1.html in the root file directory, in the following format:

[Email protected] html]# ln-sv/tmp/1.html/var/www/html/2014.html
'/var/www/html/2014.html ', '/tmp/1.html '

FollowSymLinks is then turned on by default in the configuration file, you can find 1.html by entering the URL http://192.168.1.184/2014.html, see:

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201408/10/6249823_ 1407644133jbku.png "" 244 "height="/>.

Our httpd also has the log function, the log is divided into two kinds, one is the error log, one is the Customlog access log, and the configuration file defines the path where, first see Customlog location

Customlog Logs/access_log combined

There are also error logs for: errorlog Logs/error_log

lrwxrwxrwx. 1 root root June 17:21 logs. /.. /VAR/LOG/HTTPD here is actually a link that points to the/var/log/httpd/

[Email protected] logs]# cd/var/log/httpd/
[email protected] httpd]# LL
Total 1348
-rw-r--r--1 root root 34583 9 23:24 access_log
-rw-r--r--1 root root 3874 Jul 22:07 access_log-20140727
-rw-r--r--1 root root 1280638 Jul 19:09 access_log-20140803

-rw-r--r--1 root root 22171 9 23:22 error_log
-rw-r--r--1 root root 7697 Jul 10:20 error_log-20140727
-rw-r--r--1 root root 15110 3 09:48 error_log-20140803

Our httpd service also has a good function, you can define the path alias, create a directory, just like the previous "root file directory." As below, I now define a path alias

Add alias/music/"/tmp/music/" to the configuration file and create a 23.html inside the/tmp/music.

[Email protected] music]# CD /tmp/music/
[email protected] music]# LL
Total 4
-rw-r--r--1 root root 00:10 23.html

[email protected] music]# cat 23.html
1111111111111

Then our client enters in the browser: http://192.168.1.184/music/23.html

650) this.width=650; "Style=" border-bottom:0px; border-left:0px; border-top:0px; border-right:0px "title=" image "border=" 0 "alt=" image "src=" http://img1.51cto.com/attachment/201408/10/6249823_ 1407644134xxt5.png "" 244 "height="/> Success, not with the help of the root file directory.

Next we will introduce more new features!!!!

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.