Apache configuration and application--build virtual host

1. Overview

1. Virtual Web Hosting

Run multiple Web sites on the same server, each of which does not occupy a real computer independently

2. Types of virtual hosts supported by httpd

  • Domain name-based virtual hosting
  • Virtual host based on IP address
  • Port-based virtual hosting

3. Apache access control

  • Function
    Control access to website resources
    Add access authorization to specific website directories
  • Common access control methods
    Client address restrictions
    User authorization restrictions

4. Apache connection keeps relevant parameters

1. KeepAlive
◆Whether the connection is kept open, OFF is closed, ON is opened
2. KeepAlive Timeout
◆The maximum interval time between multiple requests for one connection, the connection is disconnected after two requests exceed this time
3. MaxKeepAliveRequests
◆- -The second long connection can The maximum number of requests transferred
can be added in two ways, as shown below
Insert picture description here
Insert picture description here

2. Experimental steps

Experiment preparation

CenOS 7: Dual network cards, both in NAT mode

Win10: Single network card, using NAT mode

1. Configure DNS for domain name

1.1, configure dual network cards

ens33 : 192.168.235.135

ens36: 192,168,235,137

mark

1.2, install apache related services

yum install httpd bind -y

mark

1.3, edit the configuration file

vim /etc/named.conf

mark

1.4, edit zone configuration file

vim /etc/named.rfc1912.zones

mark

1.5, edit area details configuration file

cd / var / named

cp -p named.localhost kgc.com.zone

vim kgc.com.zone

mark

mark

1.6, copy files

cp -p kgc.com.zone benet.com.zone

1.7, start the service

systemctl start named

1.8, turn off the firewall

iptables -F

setenforce 0

mark

1.9, DNS modification of win10

The DNS of win10 is modified to: 192.168.235.135

mark

1.10, test

nslookup www.kgc.com

nslookup www.benet.com

mark

2. Construct virtual host-based on domain name

2.1, enter the configuration file directory

cd /etc/httpd/conf/

2.2. Create directories and files and edit

mkdir extra

cd extra /

vim vhost.conf

mark

mark

2.3, restart the service

systemctl start httpd

2.4, enter the website directory

cd / var / www / html

ls

mark

2.5, create a directory

mkdir kgc benet

cd kgc

vim index.html

mark

cd …

cd benet

vim index.html

mark

2.6, edit the configuration file

vim /etc/httpd/conf/httpd.conf

mark

2.7, restart the service

systemctl restart httpd

2.8, test

mark

mark

3. Build a virtual host-port based

3.1, enter the configuration file directory

cd /etc/httpd/conf/extra

3.2, edit the configuration file

vim vhost.conf

mark

3.3, create a directory

mkdir / var / www / html / benet02

vim /var/www/html/benet02/index.html

mark

3.4, edit the configuration file

vim /etc/httpd/conf/httpd.conf

mark

3.5, restart the service

systemctl restart httpd

3.6, view the process used by httpd

netstat -ntap | grep httpd

mark

3.7, test

mark

mark

4. Build a virtual host-based on IP address

4.1, enter the configuration file directory

cd /etc/httpd/conf/extra

4.2, edit the configuration file

vim vhost.conf

mark

4.3, create a directory

mkdir /var/www/html/kgc02

4.4. Create home page file

vim /var/www/html/kgc02/index.html

mark

4.5. Edit the configuration file

vim /etc/httpd/conf/httpd.conf

mark

4.6, restart the service

systemctl restart httpd

4.7, view the process of httpd

netstat -ntap | grep httpd

4.8, test

mark

mark

Guess you like

Origin blog.csdn.net/weixin_39608791/article/details/107798319