httpd配置虚拟主机三种方式——实验

简介: httpd配置虚拟主机三种方式——实验

httpd配置虚拟主机实验

配置前

[root@localhost ~]# vim /etc/httpd/conf/httpd.conf 
# If your host doesn't have a registered DNS name, enter its IP address here.
ServerName 0.0.0.0:80             //修改主配置文件
······
[root@localhost ~]# vim /usr/share/doc/httpd/httpd-vhosts.conf                                //打开虚拟主机的示例文件
[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf                                  //在con.f下创建虚拟主机配置文件,并将示例文件粘贴进去,再进行进一步的修改
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/var/www/dummy-host.example.com"
    ServerName dummy-host.example.com
    ServerAlias www.dummy-host.example.com
    ErrorLog "/var/log/httpd/dummy-host.example.com-error_log"                //错误日志
    CustomLog "/var/log/httpd/dummy-host.example.com-access_log" common              //访问日志
</VirtualHost>

同IP不同端口

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost  192.168.133.152:80>                           //80端口
        ServerName 192.168.133.152                          //域名或ip地址
        DocumentRoot /www/xiaopang                         //网站根目录
</VirtualHost>
<VirtualHost  192.168.133.152:8888>                       //8888端口
        ServerName 192.168.133.152
        DocumentRoot /www/xiaopang1
</VirtualHost>
LISTEN 8888                                                              //全局定义监听8888端口
<Directory /www>                                                       //定义/www的目录标签
        AllowOverride none                                            //.htaccess中权限不生效
        Require all granted                                             //访问控制列表允许所有主机访问
</Directory>
[root@localhost ~]# mkdir -p /www/{xiaopang,xiaopang1}
[root@localhost ~]# echo "xiaopang" > /www/xiaopang/index.html
[root@localhost ~]# echo "this is xiaopang1" > /www/xiaopang/index.html
[root@localhost xiaopang]# curl 192.168.133.152
xiaopang
[root@localhost xiaopang]# curl 192.168.133.152:8888
this is xioapang1 

不同IP同端口

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost  192.168.133.152:80>
        ServerName 192.168.133.152
        DocumentRoot /www/xiaopang
</VirtualHost>
<VirtualHost  192.168.133.153:80>
        ServerName 192.168.133.153
        DocumentRoot /www/zhongpang
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost ~]# mkdir -p /www/zhongpang
[root@localhost ~]# echo "zhongpang" > /www/zhongpang/index.html
[root@localhost xiaopang]# curl 192.168.133.152
xiaopang
[root@localhost xiaopang]# curl 192.168.133.153
zhongpang

同IP同端口不同域名

[root@localhost ~]# vim /etc/httpd/conf.d/vhosts.conf 
<VirtualHost  192.168.133.150:80>
        ServerName www.dapang.com
        DocumentRoot /www/dapang
</VirtualHost>
<VirtualHost  192.168.133.150:80>
        ServerName www.dapang.com
        DocumentRoot /www/dapang
</VirtualHost>
<Directory /www>
        AllowOverride none
        Require all granted
</Directory>
[root@localhost ~]# mkdir  /www/dapang
[root@localhost ~]# echo "dapang" > /www/dapang/index.html
[root@localhost ~]# vim /etc/hosts 
192.168.133.150 www.dapang.com www.dapang1.com
[root@localhost ~]# systemctl restart httpd.service 
[root@localhost xiaopang]# curl http://www.dapang.com
dapang
[root@localhost xiaopang]# curl http://www.dapang1.com
dapang
相关文章
|
安全 网络协议 网络安全
RH358配置Web服务器--使用 Apache HTTPD 对虚拟主机进行配置和故障排除
RH358配置Web服务器--使用 Apache HTTPD 对虚拟主机进行配置和故障排除
255 0
RH358配置Web服务器--使用 Apache HTTPD 对虚拟主机进行配置和故障排除
|
缓存 前端开发 Unix
nginx.conf配置文件各项详解(建议收藏查阅)(上)
nginx.conf配置文件各项详解(建议收藏查阅)
251 0
nginx.conf配置文件各项详解(建议收藏查阅)(上)
|
Web App开发 缓存 负载均衡
nginx.conf配置文件各项详解(建议收藏查阅)(中)
nginx.conf配置文件各项详解(建议收藏查阅)
420 0
|
应用服务中间件 Shell Apache
nginx.conf配置文件各项详解(建议收藏查阅)(下)
nginx.conf配置文件各项详解(建议收藏查阅)
190 0
|
网络协议 Apache 域名解析
LAMP环境下虚拟主机配置(基于端口)
还是在之前LAMP虚拟主机配置基于域名基础上面做,只需稍加更改即可 一、修改httpd(apache)配置文件 默认只有80端口,增加81 8080两个端口如下图所示: [root@localhost ~]# vim /etc/httpd/conf/httpd.
1341 0
|
Web App开发 域名解析 网络协议
LAMP环境下虚拟主机配置(基于IP)
本教程实验环境: [root@localhost ~]# cat /etc/redhat-release CentOS release 6.5 (Final) [root@localhost ~]# 一、首先在dns server上面配置域名解析 (1).
1250 0
|
监控 网络协议 前端开发