Apache Usage Details

Source: Internet
Author: User
Tags format definition

Apache is the world's No. 1 web server software. It can run on almost all widely used computer platforms. Because of its wide use of cross-platform and security, it is the most popular web server software. Next, we will have a deeper understanding of it through a series of experiments.

 

1. Install HTTPd service through yum

[[email protected] ~]# yum install httpd

2. Detailed description of global configuration information in the configuration file

1) Configure persistent connections

Keepalive <on | off> # Whether to enable the persistent connection function maxkeepaliverequest 100 # maximum number of requests for a persistent connection keepalivetimeout 15 # timeout of a persistent connection

2) configure the listening IP address and port

Listen [IP:] Port # sets the listening IP address and port. This option can be specified to support listening to multiple IP addresses and ports.

3) dynamic module installation and uninstallation

Loadmodule modulename/path/to/Module # You can run the following command on the terminal to view the mounted modules [[email protected] ~] # Httpd-D dump_modulesloaded modules: core_module (static) mpm_prefork_module (static) ...... dnssd_module (shared) php5_module (shared) ssl_module (shared) syntax OK

4) Specify the site root directory

DocumentRoot/path/to/DocumentRoot # define the directory where the webpage file is located

5) define the default homepage information

Directoryindex index.html index. php... # The parameters are separated by spaces.

6) path alias

Alias URL // path/# note that the "/" at the end of the URL must be consistent. If yes, both exist. If no, none exist.

7) default Character Set settings

Adddefaultcharset Character Set # common Chinese character sets are: gb2310, gb18030, GBK # general character set: UTF-8, UTF-16

8) the configuration supports CGI scripts.

ScriptAlias/cgi-bin/"/var/www/cgi-bin/" # define the CGI script execution path to the specified path <directory "/var/www/cgi-bin"> # Set access control for the CGI script path, the following describes the parameters AllowOverride none options none order allow and deny allow from all. </directory>

3. Access Control

A) ip address-Based Access Control

Order allow, deny # deny all order deny by default, allow # Allow all allow | deny from {All | ipaddr | networkaddress} by default. The networkaddress format can be 172.16 172.16.0.0 172.16.0.0/16 172.16.0.0 255.255.0.0

B) User Authentication-Based Access Control

# User-based access authentication includes basic and digest # Authentication Files include text files :. htpasswd, SQL database, DBM: database Engine and LDAP # below we configure with basic authentication based on text files #==================== ========================================= #1. make sure that the Basic Authentication Module has loaded loadmodule auth_basic_module modules/mod_auth_basic.so #2. create an authentication file and add the user # htpasswd file username #-C: Create the file when the file does not exist #-M: use MD5 to encrypt the password #-D: delete a user [[email protected] ~] # Htpasswd-C-M/etc/httpd/. passwd test1new password: Re-type new password: Adding password for user test1 [email protected] ~] # Htpasswd-M/etc/httpd/. passwd test2new password: Re-type new password: Adding password for user Test2 [[email protected] ~] # Cat/etc/httpd /. passwd test1: $ apr1 $ dgaarwek $ u04mnxh2hbrt/p5fuoj2p0test2: $ apr1 $ n4uhz492 $1l701_o982fzpqmbd594/#3. configure user authentication for the Directory [[email protected] Conf. d] # Vim Auth. conf <directory/var/www/html/auth> options none AllowOverride authconfig authtype basic # define authentication type authname "plz inout you User Info" # define authentication prompt information authuserfile/etc/httpd /. passwd # define the authentication file require valid-user # define accessible users. You can use vbalid-user to indicate all users in the file, or use User username to define specified users. </directory>



650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/53/wKioL1PnQuHQOTCBAAFhyg2-soc564.jpg "Title =" apacheuse detail 2308.png "style =" float: none; "alt =" wKioL1PnQuHQOTCBAAFhyg2-soc564.jpg "/>

 

4. Log Functions

# Error Log definition errorlog "path/to/error/logfile" # define the Error Log Level loglevel {debug | info | notice | warn | error | crit | alert | emerg} # custom log customlog "/path/to/customlog/file" log format name # custom log format definition logformat "format name # commonly used macros # % H: client address # % L: remote login name # % u: Remote Authentication Name, not authenticated as "-" # % T: request receipt time # % R: start line of the Request Message # %> S: response status # % B: Response packet length bits # % {header_name} I: record the value corresponding to the specified Header

5. MPM parameter configuration

<Ifmodule prefork. c> # If the prefork module is enabled, the following parameters take effect: startservers 8 # Number of threads started at server startup minspareservers 5 # define the minimum number of idle processes maxspareservers 20 # define the maximum number of idle processes serverlimit 256 # maximum number of processes maxclients 256 # maximum Client number of maxrequestsperchild 4000 # Number of requests per process in its lifecycle </ifmodule> #================ =====< ifmodule worker. c> startservers 4 # Number of threads started when the server is started maxclients 300 # maximum number of clients minsparethreads 25 # minimum number of idle processes maxsparethreads 75 # maximum number of idle processes threadsperchild 25 # Number of threads generated by each process maxrequestsperchild 0 # How many requests can be processed by each process in its lifecycle </ifmodule>

6. VM

(The length is long. Please read another blog and click to view it)

7. Use Apache embedded processor server-status

[[email protected] conf.d]# cat serverstatus.conf<Location /server-status>    options none    SetHandler server-status    Order allow,deny    allow from 192.168.1</Location>

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M01/45/52/wKiom1PnQcqBaGcOAAFZyTxvVPw458.jpg "Title =" apacheuse details 3286.png "style =" float: none; "alt =" wkiom1pnqcqbagcoaafzytxvvpw458.jpg "/>

8. Configure the practical HTTPS protocol for secure connection

# Install mod_ssl [[email protected] Conf. d] # Yum install mod_ssl # generate a private key for httpd and a certificate mkdir/etc/httpd/SSL; CD httpd/SSL (umask 077; openSSL genrsa-out/etc/httpd // httpd. key 1024) OpenSSL req-New-key httpd. key-out httpd. CSR # sign a certificate on the CA Certificate Server and send it back to OpenSSL ca-in httpd. CSR-out httpd. CRT-days 1000 # Configure SSL authentication sslcertificatefile/etc/httpd/SSL/httpd. CRT # specify the certificate location sslcertificatekeyfile/etc/httpd/SSL/httpd. key # specify the Private Key location

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/45/52/wKiom1PnQcvQ-hngAACkR-OMtrw924.jpg "Title =" apacheuse detail 3701.png "style =" float: none; "alt =" wKiom1PnQcvQ-hngAACkR-OMtrw924.jpg "/>

9. Use the httpd Tool

Httpd: Apache server program-T: Test-L: List static module-D dump_modules: List DSO module-M, equivalent to-T-ddump_modukles-D dump_vhosts: List All VM htpasswd: create and update user account files and Authentication Files for file Basic Authentication-C: create files. For the first time, add users to use-M: use MD5 encryption-D: delete user apachectl: httpd service control tool AB: Apache benchmark performance testing tool AB [Options] URL-C #: concurrency-N #: the total number of requests-the value of N must be greater than the value of-C #: the number of concurrent requests-N #: the total number of requests.



10. Install httpd-2.4 through source code

(The length is long. Please read another blog and click to view it)








This article from the "light" blog, please be sure to keep this source http://dddbk.blog.51cto.com/6837943/1538230

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.