基于域名的配置主机实战配置

消httpd.conf该行注视

[root@eric6 ~]#vi/application/apache/conf/httpd.conf

Includeconf/extra/httpd-vhosts.conf

[root@eric6 ~]# cd/application/apache/conf/extra/

[root@eric6 extra]#cp httpd-vhosts.conf httpd-vhosts.conf.$(date +%F)

[root@eric6extra]#vi httpd-vhosts.conf

[root@eric6 extra]#grep -v '^#' httpd-vhosts.conf


NameVirtualHost*:80


<VirtualHost*:80> //监听本机所有80端口

ServerAdmin 952773925@qq.com //系统管理的信箱

DocumentRoot "/var/blog" //网站的站点目录

ServerName www.liuyalei.com //提供网站服务的域名,需要做正规的dns解析或使用hosts测试

ServerAlias liuyalei.com //网站别名

ErrorLog "logs/blog-error_log" //错误日志文件

CustomLog "logs/blog-access_log"common //普通访问日志文件

</VirtualHost> //闭合标签




[root@eric6 extra]#/application/apache/bin/apachectl –t //检查语法

Warning:DocumentRoot [/var/blog] does not exist

httpd:apr_sockaddr_info_get() failed for eric6.4

httpd: Could notreliably determine the server's fully qualified domain name, using 127.0.0.1for ServerName

Syntax OK


[root@eric6 extra]#vi/application/apache/conf/httpd.conf

[root@eric6 extra]#grep ServerName ../../conf/httpd.conf //修改为127.0.0.1:80

# ServerName givesthe name and port that the server uses to identify itself.

ServerName127.0.0.1:80


[root@eric6 extra]#/application/apache/bin/apachectl -t

Warning:DocumentRoot [/var/blog] does not exist

Syntax OK

[root@eric6 extra]#mkdir /var/blog //创建站点目录

[root@eric6 extra]#echo '1234657' >> /var/blog/index.html

[root@eric6 extra]#/application/apache/bin/apachectl -t

Syntax OK


[root@eric6 extra]#/application/apache/bin/apachectlgraceful //平滑重启

[root@eric6 extra]#ps -ef|grep httpd

基于IP和端口的配置主机实战配置

[root@eric6 extra]#grep -v '^#' httpd-vhosts.conf


NameVirtualHost*:80


<VirtualHost 10.0.0.20:8080>

ServerAdmin 952773925@qq.com

DocumentRoot "/var/blog"

ServerName www.liuyalei.com

ServerAlias liuyalei.com

ErrorLog "logs/blog-error_log"

CustomLog "logs/blog-access_log"common

</VirtualHost>