centos配置虛擬主機virtualhost,讓服務器支持多網站多域名(轉)

如何讓centos(redhat)配置虛擬主機,讓服務器支持多個網站,針對Apache,只須要你修改apache配置文件/etc/httpd/conf/httpd.conf便可。php

裏面有個example文件,你只要對應配置便可。html

#<VirtualHost *:80>web

#    ServerAdmin webmaster@dummy-host.example.comapache

#    DocumentRoot /www/docs/dummy-host.example.comcentos

#    ServerName dummy-host.example.com服務器

#    ErrorLog logs/dummy-host.example.com-error_logdom

#    CustomLog logs/dummy-host.example.com-access_log common網站

#</VirtualHos>url

你能夠參照個人配置,在httpd.conf最底部添加:spa

NameVirtualHost *:80

<VirtualHost *:80>

ServerAdmin admin@example.com

DocumentRoot /var/www/html

ServerName www.phpddt.com 

#ErrorLog /var/log/httpd/phpddt/error_log

#注意,這裏我設置了以天爲單位生產日誌

ErrorLog "|rotatelogs /var/log/httpd/phpddt/error_log%Y_%m_%d.log 86400 480"

#CustomLog /var/log/httpd/phpddt/access_log common

CustomLog "|rotatelogs /var/log/httpd/phpddt/access_log%Y_%m_%d.log 86400 480" common

</VirtualHost>

<VirtualHost *:80>

ServerAdmin admin@example.com

DocumentRoot /var/www/html/blog

ServerName blog.phpddt.com

ErrorLog /var/log/httpd/blog/error_log

CustomLog /var/log/httpd/blog/access_log common

</VirtualHost>
如上我配置了兩臺虛擬主機:域名分別爲www.phpddt.com  blog.phpddt.com
注意,重啓apache後才生效(service httpd restart) 

若是讀者有什麼不理解,強烈建議我以前其它相關文章:

1.無需配置虛擬主機如何給網站添加二級域名

2.經過url轉發添加二級域名

3.apache如何天天生成獨立日誌文件

相關文章
相關標籤/搜索