2012年7月30日 星期一

OS X 10.8 的 Apache 相關設定

上週升級到 OS X10.8 Mountain Lion 美洲獅(還是山獅好聽),剛才發現本機的網站開不起來、偏好設定→共享裡面原本的「網頁共享」,也就是內建的 Apache 的開關也消失了。

筆記一下我自己的相關設定:

  1. 10.8 Server 以外的版本把網頁共享拿掉了VirtualHost X 的作者做了一個偏好設定面板,可以用來開關 Apache:Web Sharing in OS X Mountain Lion

  2. /etc/apache2 下舊的 httpd.conf 被更名為 httpd.conf~previous,需要手動 Merge 一下:

    • 新的 Apache 中個人設定挪到 /etc/apache2/users 下的 用戶名.conf(這裡的用戶名就是 /Users/ 下的個人資料夾名稱),檔案權限為 644 root:wheel;參考 Options (Apache: The Definitive Guide) 加上 Includes (Server-side includes) 跟 FollowSymLinks

      <Directory "/Users/用戶名/Sites/">
          Options Indexes MultiViews Includes FollowSymLinks
          AllowOverride All
          Order allow,deny
          Allow from all
          Header set Access-Control-Allow-Origin *
          DirectoryIndex index.html index.php index.shtml
      </Directory>
      
    • /etc/apache2/httpd.conf Server-side include 跟 VirtualHosts 設定:

      + Listen 8080
      
      #uncomment following settings:
      AddType text/html .shtml
      AddOutputFilter INCLUDES .shtml
      Include /private/etc/apache2/extra/httpd-vhosts.conf
      
    • /etc/apache2/extra/httpd-vhosts.conf

      NameVirtualHost *:80
      
      <VirtualHost *:80>
          DocumentRoot "/Users/Irvin/Sites/"
          Header set Access-Control-Allow-Origin *
      </VirtualHost>
      
      <VirtualHost *:80>
          DocumentRoot "/Users/Irvin/Sites/moztw"
          ServerName moztw
          DirectoryIndex index.html index.php index.shtml
      </VirtualHost>
      
      <VirtualHost *:8080>
          DocumentRoot "/Users/Irvin/Sites/moztw"
          DirectoryIndex index.html index.php index.shtml
      </VirtualHost>
      

3 意見:

匿名 提到...

這篇文張真受用,

所以是說 10.8 後的設定檔是 /etc/apache2/httpd.conf~previous,需要手動 Merge 一下又是什麼意思呢?

irvin 提到...

10.8 會把原本 10.7 中的 httpd.conf 更名為 httpd.conf~previous,然後自動建立一個全新的 httpd.conf。

所以要不就把新的砍掉,把舊的檔名改回來,要不就是跟我一樣,比對兩個檔案的內容差別,順便重新檢視一下需求,把需要的設定複製進新的檔案中。

Unknown 提到...

我的server版內也是沒有看到這個設定!
所以應該和是不是server版沒有關係!
提供給其他朋友參考!