apache学习五基于端口和ip的虚拟主机

1、基于端口的可以在主配置文件和可以在extra
2、修改主配置文件
[root@python conf]# vi httpd.conf
Listen 80之后添加以下内容
Listen 8000
Listen 9000
3、修改扩展配置文件
[root@python extra]# vi httpd-vhosts.conf
NameVirtualHost *:80后面添加
NameVirtualHost *:8000
NameVirtualHost *:9000



    ServerAdmin [email protected]
    DocumentRoot "/web/html/www"
    ServerName www.wolf.com
    ServerAlias wolf.com
    ErrorLog "logs/www-error_log"
    CustomLog "logs/www-access_log" common


    ServerAdmin [email protected]
    DocumentRoot "/web/html/blog"
    ServerName blog.wolf.com
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common


    ServerAdmin [email protected]
    DocumentRoot "/web/html/bbs"
    ServerName bbs.wolf.com
    ErrorLog "logs/bbs-error_log"
    CustomLog "logs/bbs-access_log" common

"httpd-vhosts.conf" 49L, 1533C written
4、检查语法并测试
[root@python extra]# ../../bin/apachectl -t
Syntax OK
[root@python extra]# ../../bin/apachectl graceful
[root@python extra]# 
[root@python extra]# netstat  -lntup | grep 80
tcp6       0      0 :::80                   :::*                    LISTEN      24709/httpd         
tcp6       0      0 :::8000                 :::*                    LISTEN      24709/httpd         
[root@python extra]# netstat  -lntup | grep 9000
tcp6       0      0 :::9000                 :::*                    LISTEN      24709/httpd         
[root@python extra]# 
[root@python extra]# curl -I http://bbs.wolf.com:9000
HTTP/1.1 200 OK
Date: Sun, 06 Nov 2016 15:23:09 GMT
Server: Apache/2.2.31 (Unix)
Last-Modified: Sun, 06 Nov 2016 14:47:39 GMT
ETag: "23b6535-14-540a2fd214556"
Accept-Ranges: bytes
Content-Length: 20
Content-Type: text/html


[root@python extra]# curl -I http://blog.wolf.com:8000
HTTP/1.1 200 OK
Date: Sun, 06 Nov 2016 15:23:21 GMT
Server: Apache/2.2.31 (Unix)
Last-Modified: Sun, 06 Nov 2016 14:47:39 GMT
ETag: "637e44-15-540a2fd214556"
Accept-Ranges: bytes
Content-Length: 21
Content-Type: text/html
[root@python extra]# curl -I http://wolf.com     
HTTP/1.1 200 OK
Date: Sun, 06 Nov 2016 15:23:42 GMT
Server: Apache/2.2.31 (Unix)
Last-Modified: Sun, 06 Nov 2016 14:47:39 GMT
ETag: "64482bf-14-540a2fd214556"
Accept-Ranges: bytes
Content-Length: 20
Content-Type: text/html


================================================================
基于ip虚拟主机
主机上添加多个ip
在vhost配置文件里先把监听注释掉
配置文件模块监听改为ip(主配置文件里可修改可不修改)
配置文件模块把域名修改为ip
然后重启 测试。
================================================================
以上学习了基于域名 端口 ip,很多组合,混合使用

你可能感兴趣的:(apache)