iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 9
2
Software Development

網頁後端的30件小事系列 第 9

Apache設置手把手(macOS)

前言

跟Nginx一樣,要先知道conf檔在哪,才能設定;但不同環境位置可能不同,所以使用以下指令找出conf檔的路徑。

$ apachectl -V | grep SERVER_CONFIG_FILE

https://ithelp.ithome.com.tw/upload/images/20200924/20129556D8E6wzarUe.png

所以可以知道conf檔在這裏:/usr/local/etc/httpd/httpd.conf

重開

$ sudo apachectl -k restart

The -k will force a restart immediately rather than asking politely to restart when apache is good and ready

查看Apache版本

$ httpd -v

基本設置

可以直接看這篇,這篇寫的很詳細。

macOS 10.15 Catalina Apache Setup: Multiple PHP Versions

Virtualhost

假設有兩個網站web1.comweb2.com,可以讓他們都連線到同一個ip的同一個port,再根據名字導到不同專案目錄。總之可以在同一台伺服器放多個網站專案。

在conf檔中加入以下設置。

<Virtualhost *:80>
    Documentroot <web1專案路徑>
    Servername web1.com
</Virtualhost>

<Virtualhost *:80>
    Documentroot <web2專案路徑>
    Servername web2.com
</Virtualhost>

所以當網址輸入web1.comweb2.com時,會跟DNS換到同一組ip,然後連到同一台伺服器的預設port:80。到了port:80,Apache會在判定,是什麼Servername就會導到對應的Documentroot

延伸閱讀

後來發現上面文章的作者也有寫詳細virtualhost的教學,所以也可以參考一下。

macOS 10/15 Catalina Apache Setup: MySQL, Xdebug & More...


上一篇
Nginx設置手把手(macOS)
下一篇
HTML的 id 和 name
系列文
網頁後端的30件小事30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言