Httpd/apache Compiling and installing configuration

Source: Internet
Author: User
Tags install openssl pkill

HTTP Introduction
HTTPD is the main program of the Apache Hypertext Transfer Protocol (HTTP) server. is designed as a stand-alone background process that establishes a pool of child processes or threads that process requests.

HTTPD characteristics

    1. Highly modular: Core+modules
    2. Dso:dynamic Shared ojbect dynamic Add/Unload
    3. Mpm:multi-processing module multi-channel processing modules
    4. Virtual Host: Ip,port,fqdn
    5. CGI: Universal Gateway Interface
    6. The difference between the reverse proxy (and the forward proxy) is that the forward proxy is near to the client and accelerates the client's access speed; The reverse proxy is close to the server and can be dispatched to forward the client's request to a client< in the WEBSRV cluster--->proxy (cache) <--->reverse proxy<--->websrv1,websrv2,sebsrnv)
    7. Load Balancing
    8. Path aliases
    9. Two-way authentication
    10. Support for third-party modules

HTTPD Common Configuration
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.

Apache server listens on port 80 by default
A machine can have 1 to No. 65535 ports, one port representing 2 bytes

Netstat-an This command is used to query which ports on this machine are being monitored

NETSTAT-ANB This command is used to query which ports on this machine are being monitored and their corresponding applications
Port number 1-1024 is known as the ports, these ports are generally not used, they have been allocated

How Apache Configures ports:
The port of the Apache software is configured in the httpd.conf file, which is under the Conf file in the Apache directory. In this file, you can modify the port, and then restart Apache after modifying it to take effect.

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
Lab Environment Description:

Host name IP
[[Email protected] ~] 192.168.47.12.24

Prepare the environment, and the firewall and SELinux

[[email protected] ~]# setenforce 0[[email protected] ~]#  systemctl stop firewalld

Install the development environment

Create Apache group and user Apache

[[email protected] ~]# groupadd -r apache[[email protected] ~]# useradd -M -s /sbin/nologin -g apache apache[[email protected] ~]# id apacheuid=1000(apache) gid=996(apache) 组=996(apache)

Install the related packages

[[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] ~]# yum -y install wget[[email protected] ~]# wget http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.bz2[[email protected] ~]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2

Unzip the package to download and install apr-1.4 and apr-util-1.4+

[[email protected] ~]# tar xf apr-1.6.3.tar.bz2 [[email protected] ~]# tar xf apr-util-1.6.1.tar.bz2 [[email protected] ~]# lsanaconda-ks.cfg  apr-1.6.3  apr-1.6.3.tar.bz2  apr-util-1.6.1  apr-util-1.6.1.tar.bz2

Entering apr-1.6.3 will modify the Configure configuration file

[[email protected] ~]# cd apr-1.6.3/[[email protected] apr-1.6.3]# vim configurecfgfile=${ofile}T    trap "$RM \"$cfgfile\"; exit 1" 1 2 15    #$RM "$cfgfile"      //将此行加入注释,或者删除此行

Compiling the installation

[[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

Compiling and installing httpd

[[email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2[[email protected] ~]# lsanaconda-ks.cfg  httpd-2.4.34.tar.bz2[[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 > --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

When different ports on the same IP

[[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 <virtualhost 192.168.47.12:80> documentroot "/usr/local/apache/htdocs/yan" Errorlog "Logs/yan/error_log" Customlog "Logs/yan/access_log" combined <directory "/usr/local/apache/htdocs/yan" &        Gt <RequireAll> Require all granted </RequireAll> </directory></virtualhost><virt Ualhost 192.168.47.12:81> documentroot "/usr/local/apache/htdocs/yyl" errorlog "Logs/yyl/error_log" CustomLog "Lo Gs/yyl/access_log "Combined <directory"/usr/local/apache/htdocs/yyl "> <RequireAll> Require al L granted </RequireAll> </directory></virtualhost>[[email protected] ~]# tail-25/etc/ht Tpd24/httpd.conf[[email protected] ~]# cd/usr/local/apache/logs///Establish directory with the same path as the httpd master profile [[Email protecte D] logs]# mkdir yan[[email Protected] logs]# mkdir yyl[[email protected] logs]# cd/usr/local/apache/htdocs///Create the same directory under the Site directory [[EMAIL&N Bsp;protected] htdocs]# mkdir yan[[email protected] htdocs]# mkdir yyl[[email protected] htdocs]# chown-r APA che.apache/usr/local/apache/htdocs///the directory to which the site is stored changes to the main group of apache[[email protected] htdocs]# echo ' Hello Yan ' > Yan /index.html[[email protected] htdocs]# echo ' Hello Yyl ' > yyl/index.html[[email protected] htdocs]# CD/ Usr/local/apache/bin/[[email protected] bin]#/apachectl start[[email protected] bin]#./apachectl-t

Client Authentication

Same port with different IP

[[email protected] bin]# vim/etc/httpd24/httpd.conf<virtualhost 192.168.47.12:80> DocumentRoot "/usr/ Local/apache/htdocs/yan "errorlog" Logs/yan/error_log "Customlog" Logs/yan/access_log "combined <Directory"/usr /local/apache/htdocs/yan "> <RequireAll> Require all granted </RequireAll> </dire   Ctory></virtualhost><virtualhost 192.168.47.13:80> documentroot "/usr/local/apache/htdocs/yyl" Errorlog "Logs/yyl/error_log" Customlog "Logs/yyl/access_log" combined <directory "/usr/local/apache/htdocs/yyl" &        Gt <RequireAll> Require all granted </RequireAll> </directory></virtualhost>[[email& nbsp;protected] bin]# IP addr Add 192.168.47.13/24 dev ens32 create temporary ip[[email protected for edit files] ~]# pkill httpd[[email  protected] ~]#/usr/local/apache/bin/httpd[[email protected] ~]# ss-antl[[email protected] ~]# CD/ usr/local/apache/bin/[[email Protected] bin]#/apachectl starthttpd (PID 62137) already running[[email protected] bin]#./apachectl-tsyntax OK 

Client detection

Same IP same port different domain name
[Email protected] ~]# vim/etc/httpd24/httpd.conf
<virtualhost 192.168.47.12:80>
ServerName www.yanyinglai.com:80
DocumentRoot "/usr/local/apache/htdocs/yan"
Errorlog "Logs/yan/error_log"
Customlog "Logs/yan/access_log" combined
<directory "/usr/local/apache/htdocs/yan" >
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>

<virtualhost 192.168.47.12:80>
ServerName www.yyl.com:80
DocumentRoot "/usr/local/apache/htdocs/yyl"
Errorlog "Logs/yyl/error_log"
Customlog "Logs/yyl/access_log" combined
<directory "/usr/local/apache/htdocs/yyl" >
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>

[Email protected] ~]# Pkill httpd
[Email protected] ~]#/USR/LOCAL/APACHE/BIN/HTTPD
[Email protected] ~]# Ss-antl
[Email protected] ~]# cd/usr/local/apache/bin/
[[email protected] bin]#./apachectl start
HTTPD (PID 62137) already running
[Email protected] bin]#./apachectl-t
Syntax OK

Client detection
Modify on Windows pc, C:\Windows\System32\drivers\etc file

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.