Tommy 碎碎念

Tommy Wu's blog

« 上一篇 | 下一篇 »

Gallery 3 在 Nginx 下的安裝與設定
post by tommy @ 15 十二月, 2011 10:00

由於 Gallery 3 大幅的簡化, 所以在安裝使用上, 並不像 Gallery 2 一樣有那麼多的 rewrite 要處理, 相對來說是簡單許多. 原則上只要 nginix 底下的 php 設定是正確的, 而且可以正確使用 PATH_INFO 就可以運作了.

  • 在  ngnix 上頭, 應該只要下面的設定就可以有基本的運作:
location / {
if (!-e $request_filename) {
rewrite ^/index\.php/(.+)$ /index.php?kohana_uri=$1 last;
rewrite ^/(.+)$ /index.php?kohana_uri=$1 last;
rewrite ^/$ /index.php?kohana_uri=/ last;
}
try_files $uri $uri/ =404;
}

因為 Gallery 3 是用  kohana 這個 PHP framework 寫的, 所以 URL 實際都是轉成 kohana_uri 這個變數去處理. 第一個 rewrite 是把 PATH_INFO 轉成 kohana_uri, 第二個 rewrite 是不使用 index.php 時, 一樣把 PATH_INFO 轉成 kohana_uri, 第三個 rewrite 是主頁面的轉換.

  • 接著是相簿的封面縮圖的處理:
location ~ /\.album\.jpg {
allow all;
access_log off;
log_not_found off;
}

在 Gallery 3 是用 .album.jpg 這個檔名來當成封面, 一般來說, 在 nginx 上, 我們可能會把 .xxx 的檔案給 deny 掉, 如果有這類的處理, 在這條 rule 之前, 記得加上對 .album.jpg 的處理, 否則會看不到封面縮圖.

# for gallery remote
location ~ ^/main\.php$ {
return 404;
}
location ~ ^/gallery_remote2\.php$ {
rewrite ^/gallery_remote2\.php(.*)$ /index.php?kohana_uri=/gallery_remote$1 last;
}

只要把 /gallery_remote2.php 轉向處理就可以. 另外, 記得把 modules/gallery/config/cookie.php 裡頭的 $config['httponly'] 改成 false 才可以讓 Gallery Remote 正常連線.

  • 對於 /var 路徑下頭檔案的管理:
location ~ ^/var/(albums|resizes|thumbs)/ {
rewrite ^(.*)$ /index.php?kohana_uri=/file_proxy/$1 last;
}
location ~ ^/var/(logs|tmp|uploads)/ {
deny all;
}

由於 Gallery 3 又把資料放回程式所在的目錄下, 不像 Gallery 2 是放在其他的目錄, 所以.... 只要有人知道正確的 URL, 就可以存取到 /var 下頭的檔案. 因此, 我們必須加上這些目錄的設定. 其中 logs, tmp, uploads 是完全不允許存取的. 而 albums, resizes, thumbs 在預設的情形下, 是完全沒有限制的... 而且在 Gallery 3 的正常運作下, 它只針對 Apache 來處理, 也就是當你對某個相簿做權限管理之後, 才會在該相簿的目錄下加上一個 .htaccess 的檔案來做 rewrite 到 /file_proxy/ 去檢查. 但是... nginx 完全不看 .htaccess (而且 rewrite 寫法也不同), 所以... 對於 nginx 來說, 最好是直接把這些目錄都轉給 /file_proxy/ 去處理. 就算你是用 Apache, 我也建議用同樣的設定, 因為... 有些模組會加上密碼或隱藏的功能, 如果不做這個轉向, 就會跳過這部份的權限檢查 (實際上就算轉向也會跳過檢查, 還是要改一下程式才可以).

  • 把 /index.php 由 URL 移除:
diff -Nur gallery3.orig/application//config/config.php gallery3/application//config/config.php
--- gallery3.orig/application//config/config.php 2011-05-25 12:04:04.000000000 +0800
+++ gallery3/application//config/config.php 2011-12-12 12:50:29.634534543 +0800
@@ -54,7 +54,8 @@
*
* This can be removed by using URL rewriting.
*/
-$config["index_page"] = isset($_GET["kohana_uri"]) ? "" : "index.php";
+//$config["index_page"] = isset($_GET["kohana_uri"]) ? "" : "index.php";
+$config["index_page"] = "";
 
/**
* Fake file extension that will be added to all generated URLs. Example: .html

就是把 $config['index_page'] 設成空的就可以.

  • 把 wind 的畫面寬度變大:
diff -Nur gallery3.orig/themes//wind/css/screen.css gallery3/themes//wind/css/screen.css
--- gallery3.orig/themes//wind/css/screen.css 2011-05-25 12:04:04.000000000 +0800
+++ gallery3/themes//wind/css/screen.css 2011-12-12 12:57:51.173943714 +0800
@@ -397,10 +397,14 @@
position: relative;
}
 
+#doc4 {
+ width: 99%;
+}
+
#g-content {
padding-left: 20px;
position: relative;
- width: 696px;
+ width: 98%;
}
 
#g-sidebar {

把寬度用百分比來算, 記得加上 #doc4 的處理才有作用.

  • 把除錯的訊息打開, 在 Gallery 3 的目錄加上 local.php, 內容如下:
<? defined("SYSPATH") or die("No direct script access");
error_reporting(E_ALL);
ini_set('display_errors', true);

因為.... Galley 3 感覺並不像完成品.... 所以, 把除錯訊息打開才方便找問題發生點. 

Del.icio.us Furl HEMiDEMi Technorati MyShare
commons icon [1] Re:Gallery 3 在 Nginx 下的安裝與設定 [ 回覆 ]

亲爱的朋友:
您好!
我在nginx上安装gallery3.0是发现无法登陆.在这里想得到你的帮助,谢谢!

commons icon [2] Re:Gallery 3 在 Nginx 下的安裝與設定 [ 回覆 ]

一般應該是 php 的 PATH_INFO 那邊沒處理到吧.
如果你認為與 PATH_INFO 無關的話, 那我也想不出為什麼了.

迴響
暱稱:
標題:
個人網頁:
電子郵件:
authimage

迴響

  

Bad Behavior 已經阻擋了 51 個過去 7 天試圖闖關的垃圾迴響與引用。
Power by LifeType. Template design by JamesHuang. Valid XHTML and CSS