Article directory
foreword
Make a correction and supplement to the previous blog (17)
Based on different port numbers, realize the deployment and access of multiple virtual hosts
describe | IP address |
---|---|
Apache server | 192.168.118.115 |
116.xxx.com | 192.168.118.115:80 |
117.xxx.com | 192.168.118.115:81 |
1. Apache server deployment
Apache is a web server provider, web middleware, can run on a variety of operating systems, can provide the transmission of html text documents, the transmission protocol is http/https protocol, default port: 80/443
1. Configure yum source
Enter the yum configuration directory
cd /etc/yum.repos.d
create backup
mkdir backup
Move the CentOS-* files into the backup folder
mv CentOS-* backup
create a new file
vim local.repo
document content
[local]
name=local
baseurl=file:///mnt
enabled=1
gpgcheck=0
Unmount the CD-ROM
umount /dev/sr0
load CD-ROM
mount /dev/sr0 /mnt
2. Close the firewall, network graphical tools and SElinux
Close the firewall and prohibit the firewall from starting
systemctl stop firewalld && systemctl disable firewalld
close network grapher
systemctl stop NetworkManager && systemctl disable NetworkManager
View SElinux status
getenforce
Set permissive mode (temporarily turn off SElinux)
setenforce 0
Disable SElinux permanently
vim /etc/selinux/config
SELINUX=enforcing
changed to
SELINUX=disabled
3. Configure static IP
Enter the network card configuration directory
cd /etc/sysconfig/network-scripts/
Edit network card configuration
vim ifcfg-ens33
document content
TYPE=Ethernet
BOOTPROTO=static
NAME=ens33
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.
PREFIX=24
GATEWAY=
DNS=
Restart the network service after configuring the network card
systemctl restart network
4. Install the Apache package
The Apache package is bind
yum -y install httpd
5. Core configuration file
(1) A single web page can be used without multiple configurations
The main configuration file directory is
/etc/httpd/conf/httpd.conf
(2) Multi-page configuration
1) Based on different port numbers
2) Based on different domain names
3) Based on different IP addresses
This blog is based on different port number configurations:
configure the virtual host header as follows
Create a directory
mkdir /etc/httpd/extra
Copy a file virtual host header configuration file to the current directory
cp /usr/share/doc/httpd-2.4.6/httpd-vhosts.conf /etc/httpd/extra
Append at the end of the main configuration file
vim /etc/httpd/conf/httpd.conf
IncludeOptional extra/*.conf
Comment out Listen 80 in httpd.conf
vim /etc/httpd/conf/htppd.conf
#Listen 80
Add in httpd-vhosts.conf: Listen 80, Listen 81
vim /etc/httpd/extra/httpd-vhosts.conf
listen 80
listen 81
<VirtualHost 192.168.118.115:80>
ServerAdmin root
DocumentRoot "/var/www/html/115/"
ServerName 115.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/115.com-error_log"
CustomLog "/var/log/httpd/115.com-access_log" common
</VirtualHost>
<VirtualHost 192.168.118.115:81>
ServerAdmin root
DocumentRoot "/var/www/html/116/"
ServerName 115.com
ServerAlias www.dummy-host.example.com
ErrorLog "/var/log/httpd/116.com-error_log"
CustomLog "/var/log/httpd/116.com-access_log" common
</VirtualHost>
6. Restart the Apache server
systemctl restart httpd
7. The client accesses the Apache server for authentication
When the client device is in the same network segment as the Apache server, it can be accessed through the ip address.