加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

配置Apache虚拟主机

发布时间:2020-12-13 14:16:47 所属栏目:Linux 来源:网络整理
导读:h2 id="实验环境"实验环境 一台最小化安装的CentOS 7.3虚拟机 yum install -y httpd mkdir /var/wwwrootmkdir /var/wwwroot/site1mkdir /var/wwwroot/site2echo -e "site1" >> /var/wwwroot/site1/index.htmlecho -e "site2" >> /var/wwwroot/site2/index.ht

<h2 id="实验环境">实验环境

  1. 一台最小化安装的CentOS 7.3虚拟机

yum install -y httpd

mkdir /var/wwwroot
mkdir /var/wwwroot/site1
mkdir /var/wwwroot/site2
echo -e "site1" >> /var/wwwroot/site1/index.html
echo -e "site2" >> /var/wwwroot/site2/index.html

setenforce 0
systemctl stop firewalld
systemctl disable firewalld

vim /etc/httpd/conf.d/vhost.conf

Listen 8081

    DocumentRoot "/var/wwwroot/site1"
    ErrorLog "logs/site1.error.log"
    CustomLog "logs/site1.access.log" common
    

Listen 8082
<VirtualHost *:8082>
DocumentRoot "/var/wwwroot/site2"
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted

systemctl start httpd

http://192.168.204.133:8081http://192.168.204.133:8082

vim /etc/httpd/conf.d/vhost.conf


    DocumentRoot "/var/wwwroot/site1"
    ServerName site1.test.com
    ErrorLog "logs/site1.error.log"
    CustomLog "logs/site1.access.log" common
    

<VirtualHost *:80>
DocumentRoot "/var/wwwroot/site2"
ServerName site2.test.com
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted

systemctl restart httpd

hosts文件

编辑C:WindowsSystem32driversetchosts文件, 添加以下内容(根据实际情况自己修改)

192.168.204.135   site1.test.com  
192.168.204.135   site2.test.com

http://site1.test.com/http://site2.test.com/

ifconfig ens33:1 192.168.204.135
ifconfig ens33:2 192.168.204.136

vim /etc/httpd/conf.d/vhost.conf


    DocumentRoot "/var/wwwroot/site1"
    ErrorLog "logs/site1.error.log"
    CustomLog "logs/site1.access.log" common
    

<VirtualHost 192.168.204.136:80>
DocumentRoot "/var/wwwroot/site2"
ErrorLog "logs/site2.error.log"
CustomLog "logs/site2.access.log" common
<Directory "/var/wwwroot/site2">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted

systemctl restart httpd

http://192.168.204.135/http://192.168.204.136/

本文链接:

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读