Ubuntu18系統Apache添加虛擬域名

ubuntu環境下,爲apache添加虛擬域名,有點類似於nginx。但是在添加了軟鏈接之後,還是沒有成功。

  • 先在hosts裏面添加域名指向虛擬機IP地址
vim /etc/hosts
127.0.1.1   tp.test
  • 項目目錄爲/mnt/e/www/tp_test,進入 /etc/apache2/sites-available目錄,複製默認配置文件 000-default.conftptest.conf, 具體命令如下:
cd  /etc/apache2/sites-available/
cp  000-default.conf tptest.conf
  • 複製完成後,編輯新文件
    添加 ServerName tp.test
    修改 DocumentRoot /mnt/e/www/tp_test/public

  • 創建軟連接

cd /etc/apache2/sites-enabled
ln -s ../sites-available/tptest.conf tptest.conf
  • 修改 /etc/apache2/apache2.conf 添加如下代碼
vim /etc/apache2/apache2.conf

<Directory /mnt/e/www/tp_test>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
  • 保存重啓apache服務
    service apache2 restart

做完之後還是訪問不了,發現sites-enabled目錄下新建的軟鏈接是紅色的,而其他的軟鏈接都是藍色。
在建立軟鏈接的時候,使用絕對路徑就成功了。

ln -s /etc/apache2/sites-available/tptest.conf /etc/apache2/sites-enabled/tptest.conf

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章