apache服务器基于ip以及基于端口的虚拟主机访问
一.基于ip地址的访问1 在apache服务器配置文件中的最后添加新配置文件
vi /etc/httpd/conf/http.conf
Include vhost/vhost.conf#vhost/vhost.conf 为新文件的相对路径,vhost.conf为新建配置文件
2 编写配置文件vhost.conf
1
2 ServerAdmin webmaster@dummy-host.example.com
3 DocumentRoot /data/web/test01 #访问页面相对路径
4 ServerName dummy-host.example.com
5 ErrorLog logs/dummy-host.example.com-error_log #日志文件路径
6 CustomLog logs/dummy-host.example.com-access_log common
7
8
9 ServerAdmin webmaster@dummy-host.example.com
10 DocumentRoot /data/web/test02#访问页面路径
11 ServerName dummy-host.example.com
12 ErrorLog logs/dummy-host.example.com-error_log
13 CustomLog logs/dummy-host.example.com-access_log common
14
3 配置虚拟网卡
ifconfig eth0:0 192.168.1.10 up
ifconfig eth0:0 192.168.1.20 up
4 重启 apache服务
service httpd restart
访问:192.168.1.10
192.168.1.20
二 基于端口的访问
1 在apache服务器配置文件中的最后添加新配置文件
vi /etc/httpd/conf/http.conf
Include vhost/vhost.conf#vhost/vhost.conf 为新文件的相对路径,vhost.conf为新建配置文件
2 编写要添加的配置文件
Listen 81 #开启端口 默认端口是80
Listen 82 #开启端口
# 192.168.1.99是本机ip
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /data/web/test01 #页面路径
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /data/web/test02
ServerName dummy-host.example.com
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common
3 重启apache服务器
service httpd restart
4 访问 192.168.1.99:81
192.168.1.99:82
页:
[1]