Compile and install httpd to achieve access to three types of virtual hosts

Source: Internet
Author: User
Tags install openssl

httpd Introduction
HTTPD is the main program for the APAHCE 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.
In general, httpd should not be called directly, but should be called by Apachectl in a Unix-like system and run as a service in Windows.

1. Compile and install httpd-2.4
httpd dependent on Apr-1.4+,apr-util-1.4+,[apr-icon]
Apr:apache Portable Runtime

            (1) Install the development environment [[email protected]~]# Yum Groupinstall "Development Tools"-Y (2) Create system users, do not Allow login not to create home directory [[[email protected] ~]# groupadd-r Apache [[email protected] ~]# useradd-r-M -s/sbin/nologin-g Apache Apache (3) Install compilation dependency package [[email protected] ~]# yum install Openssl-devel p Cre-devel expat-devel libtool-y (4) Download and install apr-1.4+ and apr-util-1.4+ [[email protected] ~]# Yum Inst                All wget-y [[email protected] ~]# cd/usr/src [[email protected] src]# ls Debug kernels//download compile install apr-1.4+ [[email protected] src]# wget http://mirrors.shu.edu.cn/ apache//apr/apr-1.6.3.tar.bz2 [[email protected] src]# tar xf apr-1.6.3.tar.bz2 [[Emai                l protected] src]# ls apr-1.6.3 apr-1.6.3.tar.bz2 debug kernels where you need to modify the apr-1.6.3 configuration file [[EMAIL&NBsp;protected] apr-1.6.3]# VI Configure if Test-n "${zsh_version+set}"; Then setopt no_glob_subst fi cfgfile=${ofile}t trap "$RM \" $CF Gfile\ "; Exit 1 "1 2 # $RM" $cfgfile "//Add this line to comment or delete [[email protected] apr-1.6.3]#./configure- -PREFIX=/USR/LOCAL/APR [[email protected] apr-1.6.3]# make && make install//download compilation installation apr-util-1.4 + [[email protected] src]# wget http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2

[Email protected] src]# Tar XF apr-util-1.6.1.tar.bz2
[[email protected] src]# ls
apr-1.6.3 apr-util-1.6.1 Debug
apr-1.6.3.tar.bz2 apr-util-1.6.1.tar.bz2 Kernels
[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
(5) Compile and install httpd
[Email protected] ~]# wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.34.tar.bz2
[[email protected] ~]# ls
Anaconda-ks.cfg httpd-2.4.34.tar.bz2
[Email protected] ~]# Tar XF httpd-2.4.34.tar.bz2
[[email protected] ~]# ls
Anaconda-ks.cfg httpd-2.4.34 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
[[email protected] httpd-2.4.34]# make && make install

    

ServerName www.example.com:80//Cancel the # number in front of this line

Three types of virtual hosts:
Different ports of the same IP
Same port with different IP
Same IP same port different domain name

    1. Different ports of the same IP
      Modify the configuration file to add a new port, the new port must be not occupied by other processes
      [Email protected] ~]# vi/etc/httpd24/httpd.conf
      Listen 80
      Listen 8080
      Add the virtual host configuration at the end of the configuration file
      <virtualhost 192.168.56.13:80>
      ServerName www.rose.com
      DocumentRoot "/usr/local/apache/htdocs/rose"
      Errorlog "/usr/local/apache/logs/rose/error_log"
      Customlog "/usr/local/apache/logs/rose/access_log" combined
      <Directory/usr/local/apache/htdocs/rose>
      <RequireAll>
      Require all granted
      </RequireAll>
      </Directory>
      </VirtualHost>

<virtualhost 192.168.56.13:8080>
ServerName www.rose.com
DocumentRoot "/usr/local/apache/htdocs/huaer"
Errorlog "/usr/local/apache/logs/huaer/error_log"
Customlog "/usr/local/apache/logs/huaer/access_log" combined
<Directory/usr/local/apache/htdocs/huaer>
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>
Create a Web page directory and modify the genus Master Group
[Email protected] ~]# cd/usr/local/apache/htdocs/
[[email protected] htdocs]# ls
Index.html
[Email protected] htdocs]# mkdir rose Huaer
[email protected] htdocs]# LL
Total 4
Drwxr-xr-x. 2 root root 6 14:50 Huaer
-rw-r--r--. 1 root root on June index.html
Drwxr-xr-x. 2 root root 6 14:50 Rose
[Email protected] htdocs]# chown Apache.apache rose-r
[Email protected] htdocs]# chown Apache.apache huaer-r
[email protected] htdocs]# LL
Total 4
Drwxr-xr-x. 2 Apache Apache 6 14:50 Huaer
-rw-r--r--. 1 root root on June index.html
Drwxr-xr-x. 2 Apache Apache 6 14:50 Rose
Create a Web page and write content
[Email protected] htdocs]# echo ' You're my Rose, ran ' > rose/index.html
[[email protected] htdocs]# echo ' zhe huangye zui hou yi duo Meigui ' > huaer/index.html
Create the appropriate Web log directory and change the genus Master Group
[[email protected] ~]# Mkdir/usr/local/apache/logs/{rose,huaer}
[Email protected] ~]# ls/usr/local/apache/logs/
Huaer Rose
[Email protected] ~]# chown-r apache.apache/usr/local/apache/logs/
[Email protected] ~]# ll/usr/local/apache/logs/
Total 0
Drwxr-xr-x. 2 Apache Apache 6 15:05 Huaer
Drwxr-xr-x. 2 Apache Apache 6 15:05 Rose
Start the service, turn off the firewall, check the port.
[Email protected] ~]#/USR/LOCAL/APACHE/BIN/HTTPD
[Email protected] ~]# Systemctl stop Firewalld
[Email protected] ~]# Ss-antl
State recv-q send-q Local address:port Peer address:port
LISTEN 0 128::
LISTEN 0::: 8080::
:

LISTEN 0 128::: 80:::
LISTEN 0
::: From:::

Validation effect

2. Same port with different IP
Remove port 8080 based on the original configuration file
Add a new IP
[[Email protected] ~]# IP addr add 192.168.56.14/24 dev ens32
[[Email protected] ~]# IP A
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 65536 qdisc noqueue State UNKNOWN Qlen 1
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
Valid_lft Forever Preferred_lft Forever
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:ENS32: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU Qdisc pfifo_fast State up Qlen 1000
Link/ether 00:0C:29:F5:A6:C5 BRD FF:FF:FF:FF:FF:FF
inet 192.168.56.13/24 BRD 192.168.56.255 Scope Global ENS32
Valid_lft Forever Preferred_lft Forever
inet 192.168.56.14/24 Scope Global Secondary ENS32
Valid_lft Forever Preferred_lft Forever
Inet6 FE80::6C93:E6F0:10CC:2F84/64 Scope link
Valid_lft Forever Preferred_lft Forever
Modifying a configuration file
<virtualhost 192.168.56.13:80>
ServerName www.rose.com
DocumentRoot "/usr/local/apache/htdocs/rose"
Errorlog "/usr/local/apache/logs/rose/error_log"
Customlog "/usr/local/apache/logs/rose/access_log" combined
<Directory/usr/local/apache/htdocs/rose>
<RequireAll>
</RequireAll>
</Directory>
</VirtualHost>

<virtualhost 192.168.56.14:80>
ServerName www.rose.com
DocumentRoot "/usr/local/apache/htdocs/huaer"
Errorlog "/usr/local/apache/logs/huaer/error_log"
Customlog "/usr/local/apache/logs/huaer/access_log" combined
<Directory/usr/local/apache/htdocs/huaer>
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>

Restart Service
[Email protected] ~]# Pkill httpd
[Email protected] ~]#/USR/LOCAL/APACHE/BIN/HTTPD

3.相同ip相同端口不同域名

Modifying a configuration file
<virtualhost 192.168.56.13:80>
ServerName www.rose.com
DocumentRoot "/usr/local/apache/htdocs/rose"
Errorlog "/usr/local/apache/logs/rose/error_log"
Customlog "/usr/local/apache/logs/rose/access_log" combined
<Directory/usr/local/apache/htdocs/rose>
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>

<virtualhost 192.168.56.13:80>
ServerName www.huaer.com
DocumentRoot "/usr/local/apache/htdocs/huaer"
Errorlog "/usr/local/apache/logs/huaer/error_log"
Customlog "/usr/local/apache/logs/huaer/access_log" combined
<Directory/usr/local/apache/htdocs/huaer>
<RequireAll>
Require all granted
</RequireAll>
</Directory>
</VirtualHost>

Resolving domain name WinDOS system in C:\WINDOWS\SYSTEM32\DRIVERS\ETC
The apple in the/etc/hosts
Add the following in the C:\Windows\System32\drivers\etc\hosts file
192.168.56.13 www.rose.com
192.168.56.13 www.huaer.com
Validation results

Compile and install httpd to achieve access to three types of virtual hosts

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.