設定的地方有兩個:一個是/etc/hosts下的設定。另一個是/etc/apache2/site-available/000-default.conf
首先
sudo vi /etc/hosts
127.0.0.1 localhost cms.localhost
再來
sudo /etc/apache2/site-available/000-default.conf
如果Apache's版本是2.4以後的版本就改成以下的設定
<VirtualHost *:80> ServerName localhost DocumentRoot "/var/www/html" </VirtualHost>
<VirtualHost *:80>
ServerName cms.localhost DocumentRoot "/home/xxx/myweb/public" <Directory "/home/xxx/myweb/public"> DirectoryIndex index.php AllowOverride All Require all granted </Directory> </VirtualHost>
若Apache是2.4以後的版本(不含2.4),則要改成以下的設定
<VirtualHost *:80> ServerName localhost DocumentRoot "/var/www/html" //根據實際路徑設定 <Directory "/var/www/html"> //根據實際路徑設定 AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost> <VirtualHost *:80> ServerName cms.localhost DocumentRoot "/home/xxx/myweb/public" //根據實際路徑設定 <Directory "/home/xxx/myweb/public"> //根據實際路徑設定 DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all Require all granted </Directory> </VirtualHost>
都設定好之後,不要忘記了重新啟動Apache
sudo service apache2 restart
此時打開瀏覽器輸入
localhost以及cms.localhost就會出現兩個不同的網頁站台
沒有留言:
張貼留言