Httpd/apache Compiling and installing configuration

Source: Internet
Author: User

I. HTTPD INTRODUCTION 1.HTTPD is a classic implementation of the HTTP protocol and a top-level project in the Apache organization, and its official site is httpd.apache.org. Operating mechanism of 2.HTTPD

Highly modular (Core+modules): mechanism with core modules + expansion modules
DSO (Dynamic Shared Object) mechanism: can be loaded on demand dynamic loading module to achieve the corresponding function
Use of MPM (Multipath processing Moules): Three working models using a multi-channel processing module

(1) Prefork Model: Multi-process model, a master process is responsible for managing child processes, creating sockets, accepting user requests, and distributing requests to sub-processes, the child process is specifically responsible for processing user requests, working in advance to generate a number of idle processes, waiting to process user requests.

(2) Worker model: Multi-process, multithreaded model, a master process is responsible for managing child processes, creating sockets, accepting user requests, and distributing user requests to each child process, and each child process generates multiple threads, each of which is responsible for handling user requests specifically.

(3) Events: Event-driven, multi-process model, a master process responsible for managing child processes, creating sockets, accepting user requests, and handing user requests to child processes, each of which processes multiple requests based on event driven and returns the results to the client.

3.HTTPD has a wealth of functional features, commonly used are:

Support for CGI (Common gataway Interface) protocol
Support for virtual hosts: Virtual hosts can be implemented based on IP,PORT,FQDN
Support for reverse proxy mechanism
Support Load Balancing function
Has a rich authentication mechanism
Support for third-party modules
Support for Path aliases

Three. httpd common Configuration 1. Implementing a virtual Host in httpd

The so-called virtual host refers to the provision of a different configuration in the configuration file, so that can be implemented on the same physical server to provide more than one site access path, the implementation of three ways, namely:

IP address is the same, listening to different ports, through a different port number to access
Different IP addresses, ports can be the same, access by different IP
Unlike host names, the port number and IP address can be the same, accessed through different host names.
The premise of using a virtual host is to turn off the central host feature, which will comment on the documentroot in the master configuration file.

2. Persistent and non-persistent connections

When the client communicates with the server for a long period of time, the client makes a series of requests, the server responds to the requests, and the HTTP protocol establishes the connection based on the TCP protocol, so that the series of requests and responses can be sent each time through a separate TCP connection. can also be sent through the same TCP connection, each time (the transfer of each resource) is sent using different TCP is called a non-persistent connection, each time through the same TCP connection is sent by the way is called a persistent connection. To implement persistent functionality in HTTPD:

KeepAlive {On|off}: Enable or disable the persistent connection feature

Maxkeepaliverequests 100: Maximum number of client requests allowed to establish persistent connections

KeepAliveTimeout 15: Maximum Persistent connection duration per connection

3. Port number of the listener

Listen 80

4. Control access Laws
Law function
Require all granted Allow all hosts to access
Require all Deny Deny all host access
Require IP ipaddr Authorize host access to the specified source address
Require not IP ipaddr Deny host access to the specified source address
Require Host HOSTNAME Authorize host access for the specified source host name
Require not host HOSTNAME Deny host access to the specified source host name
Require not IP Deny specified IP host access
HTTPD compiling and installing the experimental Environment Description:
Host name IP
[[Email protected] ~] 192.168.24.157.24

# # #环境准备:
Shutting down firewalls and SELinux

[[email protected] ~]# systemctl stop firewalld[[email protected] ~]# systemctl disable firewalld[[email protected] ~]# sed -ri ‘s/^(SELINUX=).*/\1disabled/g‘ /etc/selinux/config[[email protected] ~]# setenforce 0
Install the development environment:
[[email protected] ~]# yum groups mark install "Development Tools"[[email protected] ~]# groupadd -r apache[[email protected] ~]# useradd -M -s /sbin/nologin -g apache apache[[email protected] ~]# yum -y install openssl-devel pcre-devel expat-devel libtool
Download and install apr-1.4+ and apr-util-1.4+
[[email protected] ~]# cd /usr/src/[[email protected] src]#yum -y install wgetwget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2ls
Unpack the package:
tar xf apr-1.6.3.tar.bz2tar xf apr-util-1.6.1.tar.bz2ls
Compile and install:
[[email protected] src]# cd apr-1.6.3cd apr-1.6.3[[email protected] apr-1.6.3]# vim configurecfgfile="${ofile}T"trap "$RM \"$cfgfile\"; exit 1" 1 2 15# $RM "$cfgfile   //将此行#号取消 或删除此行[[email protected] apr-1.6.3]# ./configure --prefix=/usr/local/apr[[email protected] apr-1.6.3]# make && make install[[email protected] apr-1.6.3]# cd /usr/src/apr-util-1.6.1[[email protected] apr-util-1.6.1]#  ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr[[email protected] apr-util-1.6.1]# make && make install

# # #编译安装httpd

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2[[email protected] ~]# ls[[email protected] ~]# tar xf httpd-2.4.34.tar.bz2[[email protected] ~]# cd httpd-2.4.34[[email protected] httpd-2.4.34]# ./configure --prefix=/usr/local/apache \ //网站发布存放的目录> --sysconfdir=/etc/httpd24 \    //httpd编译安装的主配置文件> --enable-so > --enable-ssl > --enable-cgi > --enable-rewrite > --with-zlib > --with-pcre > --with-apr=/usr/local/apr > --with-apr-util=/usr/local/apr-util/ > --enable-modules=most > --enable-mpms-shared=all > --with-mpm=prefork[[email protected] ~]# make && make install

#虚拟主机:
There are three types of virtual hosts

Different ports of the same IP

Same port with different IP

Same IP same port different domain name

1. When different ports on the same IP: edit httpd to compile and install the main configuration file
[[email protected] ~]# vim/etc/httpd24/httpd.conf//find servername www.example.com:80 Cancel # comment//Find Listen 80 Add different ports below Listen 81//Add the following on the last side #virtual host 1<virtualhost 192.168.24.157:80> documentroot "/usr/local/apache /htdocs/lin "//Store website path errorlog" Logs/lin/error_log "Customlog" Logs/lin/access_log "combined <directory"/usr/loc Al/apache/htdocs/lin "> <RequireAll> Require all granted </RequireAll> </director Y></virtualhost> #virtual Host 2<virtualhost 192.168.24.157:81>//edit this line port number DocumentRoot "/usr/local/ Apache/htdocs/fan "errorlog" Logs/fan/error_log "Customlog" Logs/fan/access_log "combined <directory"/usr/local/ Apache/htdocs/fan "> <RequireAll> Require all granted </RequireAll> &LT;/DIRECTORY&G T;</virtualhost>[[email protected] ~]# tail-25/etc/httpd24/httpd.conf[[email protected] ~]# cd/usr /local/apache/logs///Establish directory with the same path as the httpd master profile [[emAil protected] logs]# mkdir lin[[email protected] logs]# mkdir fan[[email protected] logs]# cd/usr/ local/apache/htdocs///Create the same directory under the Site directory [[email protected] htdocs]# mkdir lin[[email protected] htdocs]# mkdir fan[[email protected] htdocs]# chown-r apache.apache/usr/local/apache/htdocs///directory changed to the site belong to the main group of apachell[ [email protected] htdocs]# echo ' Hello Lin ' > lin/index.html[[email protected] htdocs]# echo ' Hello fan ' ; Fan/index.html[[email protected] ~]# pkill httpd [[email protected] ~]# ps-ef|grep httpd[[email  Protected] ~]# Ss-natl [[email protected] ~]# cd/usr/local/apache/bin[[email protected] bin]#./apachectl St Art starts httpd service [[email protected] bin]#./APACHECTL-T//Check for syntax errors

# # #在客户端检测

2. Same port with different IP
[[email protected] ~]# vim/etc/httpd24/httpd.conf find servername www.example.com:80 Cancel # # Note Find Listen 80 Delete before listen 8 1 Add the following on the last side #virtual host 1<virtualhost 192.168.24.157:80> edit this line's IP documentroot "/usr/local/apache/htdocs/lin "Errorlog" Logs/lin/error_log "Customlog" Logs/lin/access_log "combined <directory"/usr/local/apache/htdocs/lin "> <RequireAll> Require all granted </RequireAll> </directory></virtualhos T> #virtual host 2<virtualhost 192.168.24.180:80> documentroot "/usr/local/apache/htdocs/fan" ErrorLog "logs/ Fan/error_log "Customlog" Logs/fan/access_log "combined <directory"/usr/local/apache/htdocs/fan "> <Re Quireall> Require all granted </RequireAll> </directory></virtualhost>[[email p Rotected] ~]ip addr Add 192.168.24.180/24 dev eth0//create temporary ip[[email protected for edit file] ~]# pkill httpd [[Email p Rotected] ~]# ps-ef|grep httPd[[email protected] ~]# Ss-natl [[email protected] ~]# cd/usr/local/apache/bin[[email protected] Bin ]#./apachectl start httpd Service [[email protected] bin]#./APACHECTL-T/Check for syntax errors

On-Client detection

# # #3. Same IP same port different domain name

[[email protected] ~]vim/etc/httpd24/httpd.conf find servername www.example.com:80 Cancel # # Note Find Listen 80 before deleting Listen  81 Add the following on the last side #virtual host 1<virtualhost 192.168.24.157:80> ServerName www.doudou.com:80//Add this line DocumentRoot  "/usr/local/apache/htdocs/lin" errorlog "Logs/lin/error_log" Customlog "Logs/lin/access_log" combined <Directory "/usr/local/apache/htdocs/lin" > <RequireAll> Require all granted </RequireAll> &lt ;/directory></virtualhost> #virtual host 2<virtualhost 192.168.24.157:80> ServerName www.dou.com:80// Add this line DocumentRoot "/usr/local/apache/htdocs/fan" errorlog "Logs/fan/error_log" Customlog "Logs/fan/access_log" Combi Ned <directory "/usr/local/apache/htdocs/fan" > <RequireAll> Require All granted </re Quireall> </directory></virtualhost>[[email protected] ~]# pkill httpd [[email protected] ~ ]# Ps-ef|grep httpd[[email p rotected] ~]# ss-natl [[email protected] ~]# cd/usr/local/apache/bin[[email protected] bin]#./apachectl s Tart start httpd Service [[[email protected] bin]#./APACHECTL-T/Check for syntax errors

# #在客户端检测

Modify the/etc/hosts/file on a Mac computer
IP domain
IP domain

Modify on a Windows PC

   C:\Windows\System32\drivers\etc 文件   ip  域名   ip  域名
On-Client detection

Httpd/apache Compiling and installing configuration

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.