基於域名的配置主機實戰配置html
取消httpd.conf該行注視apache
[root@eric6 ~]#vi/application/apache/conf/httpd.confapp
Includeconf/extra/httpd-vhosts.confdom
[root@eric6 ~]# cd/application/apache/conf/extra/ide
[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.confspa
NameVirtualHost*:80日誌
<VirtualHost*:80> //監聽本機全部80端口server
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>