• 欢迎访问VPS岛网站,国外VPS,国内VPS,国外服务器,国内服务器,服务器主机,测评及优惠码,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站 QQ群

apache2

Apache技术 AELY木 134次浏览 已收录 0个评论

#########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

 

 

 


VPS岛 的文章和资源来自互联网,仅作为参考资料,如果有侵犯版权的资源请尽快联系站长,我们会在24h内删除有争议的资源。丨 转载请注明apache2
喜欢 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址