Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to configure a virtual host using apache

Shulou Source: shulou.com Published: 2022-06-01 08:40:34 09月23日 Update

This article introduces you how to use apache to configure virtual hosts, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Apache source code installation depends on apr

Apr update

1. Backup

Mv / etc/yum.repos.d/CentOS-Base.repo / etc/yum.repos.d/CentOS-Base.repo.backup

2. Download CentOS-Base.repo to / etc/yum.repos.d/

Cd / etc/yum.repos.d/

Wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

3. Generate cache

Yum clean all

Yum makecache

4. Update the system

Yum update

Install apr and other library files

Yum install apr*

There are three ways to realize Apache virtual host.

Virtual Host based on IP

Port-based virtual host

Virtual host based on domain name

Disable the default host mode

Comment on the following line

# DocumentRoot "/ var/www/html"

1. Virtual host configuration based on IP

Add multiple IP for the host

Ip addr add 192.168.137.201/24 dev eth0

Add virtual host profile

Vim / etc/httpd/conf/extra/httpd-vhost.conf

DocumentRoot "/ var/www/test200"

ServerName www.test200.com

DocumentRoot "/ var/www/test201"

ServerName www.test201.com

Create a directory test200 test201 under / var/www/

Create a home page with IP 200,201

2. Port-based virtual host configuration

Based on the original line Listen 80, add one line

Listen 8080

DocumentRoot "/ var/www/test200"

ServerName www.test200.com

# the following is added on the basis of the above configuration.

DocumentRoot "/ var/www/test200-8080"

ServerName www.test200-8080.com

Create a directory under / var/www/ test200-8080

Create a home page with an IP of 200-8080

3. Virtual host configuration based on domain name

DocumentRoot "/ var/www/html/kgccom"

ServerName www.kgc.com

ErrorLog "logs/www.kgc.com.error_log"

CustomLog "logs/www.kgc.com.access_log" common

< Directory "/var/www/html" >

Require all granted

DocumentRoot "/ var/www/html/kccecom"

ServerName www.kcce.com

Note: refer to the vhost.conf configuration file and uncomment in the main configuration file

On how to use apache to configure virtual hosts to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Host virtual host configuration content file home page domain name base more comments directory port face help update good one line interest backup multiple Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Microsoft OPPO Reno vpn