在一個Apache服務器上能夠配置多個虛擬主機,實現一個服務器提供多站點服務,其實就是訪問同一個服務器上的不一樣目錄。
httpd支持多種方式的虛擬主機的配置,主要有如下種:html
域名1:www1.frank.com
頁面文件:/var/www/vhosts/www1
日誌文件:/var/log/httpd/www1
域名2:www2.frank.com
頁面文件:/var/www/vhosts/www2
日誌文件:/var/log/httpd/www2shell
[root@master ~]# mkdir -p /var/www/vhosts/www{1,2} [root@master ~]# mkdir -p /var/log/httpd/www{1,2}
打開主配置文件註釋掉這幾行服務器
# vi /etc/httpd/conf/httpd.conf #DocumentRoot "/var/www/html" #<Directory "/var/www"> # AllowOverride None # # Allow open access: # Require all granted #</Directory>
# vi /etc/httpd/conf.d/virhosts.conf #virtual host 1 <VirtualHost 192.168.138.200:80> ServerName www1.frank.com DocumentRoot "/var/www/vhosts/www1" ErrorLog "/var/log/httpd/www1/error_log" CustomLog "/var/log/httpd/www1/access_log" combined <Location /server-status> SetHandler server-status </Location> <Directory /var/www/vhosts/www1> <RequireAll> Require all granted </RequireAll> </Directory> </VirtualHost> #virtual host 2 <VirtualHost 192.168.138.200:80> ServerName www2.frank.com DocumentRoot "/var/www/vhosts/www2" ErrorLog "/var/log/httpd/www2/error_log" CustomLog "/var/log/httpd/www2/access_log" combined <Directory /var/www/vhosts/www2> <RequireAll> Require all granted </RequireAll> </Directory> </VirtualHost>