Linux 配置Apache服务器 下(虚拟主机,排错)
Linux配置Apache服务器 下(虚拟主机,排错)三.创建虚拟主机
配置域名解析机文件站点文件
配置域名解析(DNS或Hosts)保证能够正确地解析oa.abc.local、crm.abc.local。
在本示例中,我以hosts为例。
通过记事本打开C:\Windows\System32\drivers\etc\hosts进行修改。
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handled within DNS itself.
#127.0.0.1 localhost
#::1 localhost
192.168.188.22 oa.abc.local
192.168.188.22 crm.abc.local
# mkdir /opt/crm# echo 'CRM test page' >/opt/crm/index.html# mkdir /opt/oa# echo 'OA test page' >/opt/oa/index.html# cd /etc/httpd/# ls confconf.dlogsmodulesrun
# mkdir vhost-conf.d# echo "Include vhost-conf.d/*.conf" >>conf/httpd.conf 配置基于端口的虚拟主机:
# vi /etc/httpd/vhost-conf.d/vhost-ip.conf Listen 8002
Listen 8002
DocumentRoot /opt/crm/
DocumentRoot /opt/oa/
# apachectl configtest Syntax OK
# service httpd restart
Stopping httpd:
Starting httpd:
在浏览器中输入:http://192.168.188.22:8001/ 进行访问
在浏览器中输入:http://192.168.188.22:8002/ 进行访问
测试成功后,删除新添加的配置文件,恢复实验环境
# rm -i /etc/httpd/vhost-conf.d/vhost-ip.conf
rm: remove regular file `/etc/httpd/vhost-conf.d/vhost-ip.conf'? y
配置基于域名的虚拟主机:
# vi /etc/httpd/vhost-conf.d/vhost-name.conf
NameVirtualHost *:80
ServerName crm.abc.local
DocumentRoot /opt/crm/
ServerName oa.abc.local
DocumentRoot /opt/oa/
# apachectl configtest# service httpd restart 进行测试http://crm.abc.local/
http://oa.abc.local/
测试成功后,删除新添加的配置文件,恢复实验环境
# rm -i /etc/httpd/vhost-conf.d/vhost-name.conf rm: remove regular file `/etc/httpd/vhost-conf.d/vhost-name.conf'? y
四.排错
Apache启动或检查配置文件时有警告信息
# apachectl configtest 编辑httpd.conf文件
# vi /etc/httpd/conf/httpd.conf #
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
#ServerName www.example.com:80
ServerName localhost:80
#
重新启动Apache,完成
本期《配置Apache服务器》完结!
感谢您的来临!轻轻的赞一下,何乐而不为呢!
页:
[1]