城市故事想法成长励志

apache部署(四)虚拟机

2019-06-17  本文已影响0人  zhangxiaohao
介绍

虚拟机可以使一个WEB服务器同时发布多个WEB站点。
虚拟主机有三种实现方式:

基于ip地址的虚拟主机
vim /usr/local/apache/conf/httpd.conf
Inclue conf/extra/httpd-vhosts.conf 本行#去掉
mkdir /usr/local/apche/htdocs/web{1..2}
echo hello web1>usr/local/apache/htdocs/web1/index.html
echo hello web2>usr/local/apache/htdocs/web2/index.html
cd /usr/local/apche/conf/extra
vim httpd-vhosts.conf
#####更改形式如下:
<VirtualHost 192.168.22.66:80>
    DocumentRoot "/usr/local/apache/htdocs/web1"
    #ServerName dummy-host.example.com
    #ErrorLog "logs/dummy-host.example.com-error_log"
    #CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost 192.168.22.88:80>
    DocumentRoot "/usr/local/apache/htdocs/web2"
    #ServerName dummy-host2.example.com
    #ErrorLog "logs/dummy-host2.example.com-error_log"
    #CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>

DocumentRoot:站点根目录
ServerName:服务名
ErrorLog:错误日志
CustomLog:访问日志

/usr/local/apache/bin/apachectl -t # 检查配置
killall httpd
usr/local/apache/bin/apachectl
elinks http://192.168.22.66 -dump
elinks http://192.168.22.88 -dump
基于端口的虚拟机
Inclue conf/extra/httpd-vhosts.conf 本行#去掉
mkdir /usr/local/apche/htdocs/web{1..2}
echo hello web1>usr/local/apache/htdocs/web1/index.html
echo hello web2>usr/local/apache/htdocs/web2/index.html
cd /usr/local/apche/conf/extra
vim httpd-vhosts.conf
#####更改形式如下:
<VirtualHost *80>
    DocumentRoot "/usr/local/apache/htdocs/web1"
    #ServerName dummy-host.example.com
    #ErrorLog "logs/dummy-host.example.com-error_log"
    #CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
Listen 81  #开端口
<VirtualHost *:81>
    DocumentRoot "/usr/local/apache/htdocs/web2"
    #ServerName dummy-host2.example.com
    #ErrorLog "logs/dummy-host2.example.com-error_log"
    #CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
/usr/local/apache/bin/apachectl -t # 检查配置
killall httpd
usr/local/apache/bin/apachectl
elinks http://192.168.22.66 -dump
elinks http://192.168.22.66:81 -dump
基于域名的虚拟主机
vim cat /etc/hosts
####增加以下两句
192.168.22.66 web1.test.com
192.168.22.66 web2.test.com
vim /usr/local/apache/conf/httpd.conf
Inclue conf/extra/httpd-vhosts.conf 本行#去掉
mkdir /usr/local/apche/htdocs/web{1..2}
echo hello web1>usr/local/apache/htdocs/web1/index.html
echo hello web2>usr/local/apache/htdocs/web2/index.html
cd /usr/local/apche/conf/extra
vim httpd-vhosts.conf
#####更改形式如下:
<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/web1"
    ServerName web1.test.com
    #ErrorLog "logs/dummy-host.example.com-error_log"
    #CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/usr/local/apache/htdocs/web2"
    ServerName web2.test.com
    #ErrorLog "logs/dummy-host2.example.com-error_log"
    #CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
/usr/local/apache/bin/apachectl -t # 检查配置
killall httpd
usr/local/apache/bin/apachectl
elinks http:// web1.test.com  -dump
elinks http://web2.test.com  -dump
上一篇 下一篇

猜你喜欢

热点阅读