Apache website service,
Apache: http://mirror.bit.edu.cn/apache/httpd/
Software: http://mirror.bjtu.edu.cn/apache/apr/apr
Http://mirror.bjtu.edu.cn/apache/apr/apr-util
=============== Apache Introduction: process technology, high resource consumption, but stable;
MPM (multi process moudles): multi-processing module;
Apache working mode:
Process pool (prefork): Suitable for dynamic pages. Process waiting for visitors is always prepared in advance. A process corresponds to a web access request;
Thread Pool (event): Suitable for static pages. For example, if five processes are enabled first and 100 threads are enabled in each process, one thread receives one web access request;
Httpd -------> prefork ----> default
Httpd. worker -------> worker
Httpd. event --------> event
How can I change the MPM working mode of Apache with simplified installation?
======================= LAMP platform Overview:
========= Processes and threads in Apache:
1. install Apache Software:
Rpm and yum installation:
1> yum install httpd
Service httpd restart
Start the service script ------ run/usr/sbin/httpd ---- and call/etc/httpd/conf/httpd. conf;
The name of the program that actually provides the httpd service;
2> source code installation:
= Download the software package:
Http://mirror.bit.edu.cn/apache/httpd/
Http://mirror.bjtu.edu.cn/apache/apr/apr
Http://mirror.bjtu.edu.cn/apache/apr/apr-util
= Install software:
Yum-y install gcc autoconf automake make pcre-devel openssl-devel
Apr:
./Configure
Make & make install
Apr-util:
./Configure -- with-apr =/usr/local/apr
Make & make install
Httpd:
. /Configure -- prefix =/usr/local/apache -- enable-so -- enable-ssl -- enable-rewrite -- with-mpm = worker -- with-suexec-bin -- with-apr = /usr/local/apr
Make & make install
You can use the./configure -- help Command to view all options supported by the script:
-- Prefix specifies the installation home directory of the Apache httpd Program
-- Enable-so: enables modularity and supports DSO (dynamic shared object)
-- Enable-ssl supports SSL encryption
-- Enable-rewrite supports address rewriting.
-- With-mpm: Set Apache Working Mode
-- With-suexec-bin supports SUID and SGID
-- With-apr specifies the absolute path of the apr Program
2. modify the configuration file:
Main configuration file:/etc/httpd/conf/httpd. conf:
Simple Configuration:
If the above prompt says there is no standard domain name, you need to specify:
ServerName: www.chw.com: 80 ----- line 276 open the configuration, remove the comment, and then modify it;
Configuration file DETAILS parsing: The main configuration file of the Apache service consists of commands and containers. The Container starts with <container Name> and ends with </container Name>, container commands are generally valid only in the container:
1> SeverRoot command:
Set the installation home directory of the software. If the source code is used for installation, the default path is/usr/local/apache2;
2> Listen command:
Set the IP address and port number of the server listener. Port 80 of all IP addresses of the server is listened to by default. The syntax format is Listen [IP Address:] Port [Protocol]. The IP address and protocol are optional, by default, all IP addresses are monitored, and the TCP protocol is used. a configuration file can use the Listen command multiple times to enable multiple ports;
3> LoadModule command:
If you want Apache to dynamically load modules, You need to compile mod_so to the Apache core module in static mode through enable-so when compiling Apache. The purpose of this command is to load modules. Syntax format: loadModule module File name. The module File is generally located in the modules directory under the ServerRoot directory;
4> LoadFile command:
The function is similar to the preceding command. The difference is that the latter can load the module files under the modules directory through an absolute path;
5> ServerAdmin command:
When a website fails, you need to provide the customer with an email address that can help solve the problem. The role of the ServerAdmin command is to provide such an email address;
6> ServerName command:
Setting host names and ports on the server is important for URL address redirection;
7> DocumentRoot command:
Set the visible document root directory for the WEB Service Team client, that is, the root directory for the client to access the website;
8> ErrorLog command:
Locate the location of the server error log. The relative path is used by default;
9> ErrorLogFormat command:
Set the format of the error log;
10> CustomLog command:
Set the client access log file name and log format, in the format of CustomLog file name;
11> LogFormat command:
Description of the user log file format. Generally, an alias is created for the log format set by this command, and then the log format alias is called through the CustomLog command;
12> Include command:
Allows Apache to load other configuration files in the main configuration file;
13> Options command:
Set the option for a specific directory. The option can be set to None, indicating that no additional features are enabled. You can also use the following common options:
All: All options except MultiViews are enabled;
ExecCGI: allows execution of all CGI scripts in the specified directory of Options;
FollowSymlinks: Allows Options to specify the file links in the directory to files or directories outside the directory;
Indexes: If the Options directory corresponding to the URL cannot find the home page document specified by DirectoryIndex, the server will index all the files in the current directory;
14> Order command:
Control the default access status and the Order of Allow and Deny. If Order deny and allow are used, check the Deny first, and then check the Allow. When there is a conflict between the deny and allow, priority is given, the default rule is allow. If Order allow and deny are used, check the allow before checking the deny. When the allow and deny conflict, the deny takes priority. The default rule is deny;
Case study:
Order deny, allow
Deny from all: reject all;
Order Allow, Deny
Allow from all allows all;
Order Allow, Deny
Allow from 192.168.1.2 rejects all other IP addresses;
Order Allow, Deny
Allow from 192.168.1.2
Deny from All: Deny All access;
Order Deny, Allow
Deny from all
Allow from 192.168.1.2 rejects all other IP addresses;
15> IfDefine container:
Commands encapsulated by this container are processed only when the test condition is true when Apache is started. The test condition must be defined by-D When Apache is started:
Instance:
Service httpd-D UseCache-D MemCache restart
<IfDefine MemCache>
LoadModule mem_cache_module modules/mod_mem_cache.so
</IfDefine>
<IfDefine UseCache>
LoadModule cache_module modules/mod_cache.so
</IfDefine>
16> IfModule container:
This container encapsulates commands that will be processed only when the conditions are met, and determines whether the conditions are met based on whether the specified module has been loaded;
Case:
<IfModule unixd_module>
User daemon
Group daemon
</IfModule>
17> Directory container:
The commands in the container are only applicable to specific File System directories, subdirectories, and contents in directories;
18> <DirectoryMatch>
This command is similar to the preceding command, but can be directly matched using a regular expression ~ Symbol;
19> Files container:
The commands in the container are only applicable to specific files ~ Matches regular expressions;
20> FilesMatch container:
Only regular expressions are used to match the required files ,;
21> Location container:
The commands defined in the container are only valid for specific URLs. The syntax format is: <Location URL-path | URL> </Location>. To use a regular expression, you can use ~ Symbol to match;
22> LocationMathch container and VirtualHost container:
Use only regular expressions to match URLs, which is equivalent ~ Location of the symbol match;
============= Use case of a VM:
A virtual host runs multiple WEB Services on one server at the same time. Apache service supports domain name-based and IP-based virtual host types. However, we prefer domain name-based virtual hosts more often, the server can separate and parse the Website Based on the header information of the client's access to HTTTP. The client can use different domain names to access server resources in the same IP address;
1. Modify the main configuration file:
Turn on the Include conf/extra/httpd-vhosts.conf statement in the main configuration file, the Include command reads the contents of the configuration file as part of the main configuration file, in addition, the ports of the two virtual hosts should be different, so the master configuration file should listen to the two ports;
2. Modified configuration file:
3. Create the respective page root directory for two different virtual hosts:
When you access these two websites, if there is no valid DNS server, you can modify the hosts file for domain name resolution. If you need to perform IP address-based virtual host, you only need to change * to a fixed IP address. Multiple virtual hosts must be encapsulated using multiple virtualhosts;
# Prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule prefork. c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
# Worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves
<IfModule worker. c>
StartServers 4
MaxClients 300
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
</IfModule>
When the value assignment is different, what is the reminder when the service is refreshed?
* ****** Note:
By default, the number of files that can be opened by a process in the Linux kernel is 1024;
You can run the following command to modify the value:
Ulimit-n 25535 can only be temporarily valid;
Which modules are compiled by Apache by default:
3. Start the service and configure firewall rules or disable the Firewall:
Service httpd restart
Iptables-I INPUT-p tcp -- dport 80-j ACCEPT
Service iptables save