码迷,mamicode.com
首页 > Web开发 > 详细

apache2

时间:2017-05-16 23:36:49      阅读:369      评论:0      收藏:0      [点我收藏+]

标签:apache的虚拟主机

#########apache的虚拟主机#########

 

1.定义

可以让我们的一台apache服务器在访问不同域名的时候显示不同的主页

 

 

2.建立测试页

[root@localhost ~]# cd /var/www/

[root@localhost www]# mkdir virtual

[root@localhost www]# ls

cgi-bin  html  virtual

[root@localhost www]# cd virtual/

[root@localhost virtual]# mkdir money.westos.com/html -p

[root@localhost virtual]# mkdir news.westos.com/html -p

[root@localhost virtual]# echo "money.westos.com‘s page" >money.westos.com/html/index.html

[root@localhost virtual]# echo "news.westos.com‘s page" > news.westos.com/html/index.html

[root@localhost virtual]# cat money.westos.com/html/index.html

money.westos.com‘s page

[root@localhost virtual]# cat news.westos.com/html/index.html

news.westos.com‘s page

 

3.配置

[root@localhost www]# cd /etc/httpd/conf.d/    ##在子配置文件中配置

[root@localhost conf.d]# ls

autoindex.conf  php.conf  userdir.conf

manual.conf     README    welcome.conf

[root@localhost conf.d]# vim default.conf   ##未指定域名的访问都访问default

 

<Virtualhost  _default_:80>      ##虚拟主机开启的端口

        DocumentRoot "/var/www/html"     ##虚拟主机的默认发布目录

        CustomLog "logs/default.log" combined   ##虚拟主机日志

</Virtualhost>

 

[root@localhost conf.d]# systemctl restart httpd

[root@localhost conf.d]# ls

autoindex.conf  php.conf      welcome.conf

default.conf    README

manual.conf     userdir.conf

[root@localhost conf.d]# vim news.conf    ##指定域名news.westos.com的访问到指定默认发布目录中

[root@localhost virtual]# cat /etc/httpd/conf.d/news.conf

<Virtualhost *:80>

Servername "news.westos.com"

DocumentRoot "/var/www/virtual/news.westos.com/html"  ##默认发布目录

CustomLog "logs/news.log" combined

</Virtualhost>

<Directory "/var/www/virtual/news.westos.com/html">   ##默认发布目录的访问授权

Require all granted

</Directory>

[root@localhost conf.d]# cp news.conf money.conf

[root@localhost conf.d]# vim money.conf

[root@localhost conf.d]# systemctl restart httpd

 

@@@更改网页字体大小@@@

[root@localhost conf.d]# cd

[root@localhost ~]# cd /var/www/virtual/

[root@localhost virtual]# ls

money.westos.com  news.westos.com

[root@localhost virtual]# vim money.westos.com/html/index.html

[root@localhost virtual]# vim news.westos.com/html/index.html  

[root@localhost virtual]# cat money.westos.com/html/index.html

<h1>money.westos.com‘s page</h1>   ##前端语句(html)

[root@localhost virtual]# cat news.westos.com/html/index.html

<h1>news.westos.com‘s page</h1>

 

[root@localhost virtual]# systemctl restart httpd

 

4.测试

在浏览器所在主机中

[root@foundation13 Desktop]# vim /etc/hosts   ##本地解析

172.25.254.113 www.westos.com news.westos.com money.westos.com

 

 

 


本文出自 “AELY木” 博客,请务必保留此出处http://12768057.blog.51cto.com/12758057/1926247

apache2

标签:apache的虚拟主机

原文地址:http://12768057.blog.51cto.com/12758057/1926247

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!