1. 编辑/etc/httpd/httpd.conf文件
a. 注释掉默认的DocumentRoot "/usr/local/apache/htdocs"表示使用虚拟主机;
b. 启用Include /etc/httpd/extra/httpd-vhosts.conf虚拟主机选项;
2. 编辑/etc/httpd/extra/httpd-vhosts.conf文件
[root@www apache]# cd /etc/httpd/
[root@www httpd]# ll | grep extra
drwxr-xr-x 2 root root 4096 Aug 18 03:54 extra
Required modules: mod_log_config选项,此项要求使用mod_lod_config模块,那么需要编辑/etc/httpd/httpd.conf文件保证其中的
LoadModule log_config_module modules/mod_log_config.so是启用的;
虚拟主机信息为:
<VirtualHost *:80>
ServerName />
DocumentRoot "/var/www/a" #默认是/usr/local/apache/docs下,我改为/var/www/
<Directory /var/www/a> #此配置段要加上,如果不加,就表示进制访问
Options none
AllowOverride none
Require all granted #允许所有人访问,此时不在是 Order allow deny
</Directory> allow from all
ErrorLog "/var/log/httpd/a.error_log"
CustomLog "/var/log/httpd/a.custom_log" common
</VirtualHost>
<VirtualHost *:80>
ServerName />
DocumentRoot "/var/www/b"
<Directory /var/www/b>
Options none
AllowOverride none
Require all granted
</Directory>
ErrorLog "/var/log/httpd/b.error_log" #错误日志和访问日志我改目录了,如果不改就是保存在/usr/local/apache/logs中
CustomLog "/var/log/httpd/b.custom_log" common
然后创建各自的根目录
[root@www httpd]# mkdir /var/www/a
[root@www httpd]# mkdir /var/www/b
测试语法后重启服务
[root@www httpd]# httpd -t
Syntax OK
[root@www httpd]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
为虚拟主机提供主页面
a.[root@www httpd]# vim /var/www/a/index.html
<h1> works</h1>
b.[root@www httpd]# vim /var/www/b/index.html
<h1> works</h1>
测试
[root@www extra]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.85.128 />
192.168.85.128 />
[root@www httpd]# elinks --dump />
works
[root@www extra]# elinks --dump />
works
阅读(534) | 评论(0) | 转发(0) |