Linux:apache优化(8)—— 虚拟主机

基于端口

不同端口,相同ip,相同域名

vi /usr/local/httpd/conf/httpd.conf

在listen修改和添加一个
Listen 192.168.6.1:80
Listen 192.168.6.1:81

开启虚拟主机模块

Include conf/extra/httpd-vhosts.conf

去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

修改为以下内容


    ServerAdmin www.tarro1.com
    DocumentRoot "/usr/local/httpd/htdocs/a"
    ServerName www.tarro1.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common



    ServerAdmin www.taror1.com
    DocumentRoot "/usr/local/httpd/htdocs/b"
    ServerName www.tarro1.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common


基于ip

不同IP,不同域名,相同端口;基于IP的虚拟主机

Linux:apache优化(8)—— 虚拟主机_第1张图片

首先你要确定你有多个ip

vim /usr/local/httpd/conf/httpd.conf

在listen修改和添加一个
Listen 192.168.6.1:80
Listen 192.168.6.100:80

开启虚拟主机模块

Include conf/extra/httpd-vhosts.conf

去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

修改为


    ServerAdmin www.tarro1.com
    DocumentRoot "/usr/local/httpd/htdocs/a"
    ServerName www.tarro1.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common



    ServerAdmin www.taror2.com
    DocumentRoot "/usr/local/httpd/htdocs/b"
    ServerName www.tarro2.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common


基于域名

相同ip,相同端口,不同域名

vim /usr/local/httpd/conf/httpd.conf

在listen修改和添加一个
Listen 192.168.6.1:80

开启虚拟主机模块

Include conf/extra/httpd-vhosts.conf

去掉#
vim /usr/local/httpd/conf/extra/httpd-vhosts.conf

修改为


    DocumentRoot "/usr/local/httpd/htdocs/a"
    ServerName www.tarro1.com
    ErrorLog "logs/dummy-host.example.com-error_log"
    CustomLog "logs/dummy-host.example.com-access_log" common



    DocumentRoot "/usr/local/httpd/htdocs/b"
    ServerName www.tarro2.com
    ErrorLog "logs/dummy-host2.example.com-error_log"
    CustomLog "logs/dummy-host2.example.com-access_log" common

Linux:apache优化(8)—— 虚拟主机_第2张图片

你可能感兴趣的:(linux,apache,运维)