dreamer's profiledreamerPhotosBlogListsMore ![]() | Help |
|
10/25/2009 Apache2 -> Nginx之前在網路上看到有網友推薦改用 nginx,「據說」效能比較好,之前有試裝一下,但是 drupal 的 multi-site 的設定有一點點小麻煩,懶得研究,就把這件事一直拖著。昨晚,表妹來家裡泡茶,我跟著喝了兩大杯,趁晚上睡不著的時候,決定來好好實驗一下。 在 BSD 上要裝 nginx 很簡單,到 /usr/ports/www/nginx 裡打個 make install 就裝起來了,它的 php 支援則是要透過 FastCGI 的介面,這一部份其實可以透過 spawn-fcgi 來完成。之前在網路上查到的資料,說要先裝 lighttpd 然後再把它的 spawn-fcgi 複製出來再反安裝 lighttpd。我試了一下,其實 spawn-fcgi 可以單獨安裝,到 /usr/ports/www/spawn-fcgi 裡 make install 一樣輕鬆搞定。裝完 nginx 與 spawn-fcgi 之後,在 /etc/rc.conf 加入以下兩行:
然後再
將服務啟動。 ========== 先來說明一下伺服器提供的服務,這部機器上有 mysql-server 以及 web,因為之前覺得一般在學校的網路應用(網站)的使用率不會太高,負載其實不怎麼大,所以把一堆應用服務全放在同一台機器上,透過 Virtual Host 的設定提供服務。基本上大部份的服務都是利用 drupal 架設的。
========== 我將 /usr/local/etc/nginx/nginx.conf 裡的所有 server 設定全拿掉,改透過 include 的方式,將 virtual host 的設定分成一個個獨立的檔案。
===== _default.conf BEGIN =====
===== _default.conf END / sub.conf BEGIN ===== server {
listen 80;
server_name sub sub.dcsh.tp.edu.tw;
charset utf-8;
access_log /home/www/logs/sub.access.log main;
error_log /home/www/logs/sub.error.log error;
root /home/www/sites/sub.dcsh.tp.edu.tw;
location / {
index index.php index.html index.htm;
error_page 404 = @subsite;
}
location @subsite {
rewrite ^/([^/]*-[^/]*|df-olp|glcp|h1n1|nano|tmp)/(.*)$ /$1/index.php?q=$2 last;
rewrite ^/(.*)$ /index.php?q=$1 last;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
===== sub.conf END / query.conf BEGIN ===== server {
listen 80;
server_name query query.dcsh.tp.edu.tw;
charset utf-8;
access_log /home/www/logs/query.access.log main;
error_log /home/www/logs/query.error.log error;
root /home/www/sites/query.dcsh.tp.edu.tw;
location / {
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}===== query.conf END / gallery.conf BEGIN ===== server {
listen 80;
server_name gallery gallery.dcsh.tp.edu.tw;
charset utf-8;
access_log /home/www/logs/gallery.access.log main;
error_log /home/www/logs/gallery.error.log error;
root /home/www/sites/gallery.dcsh.tp.edu.tw;
location / {
index index.php index.html index.htm;
error_page 404 = @gallery;
}
location @gallery {
rewrite ^/d/([0-9]+)-([0-9]+)/([^?]+)$ /main.php?g2_view=core.DownloadItem&g2_itemId=$1&g2_serialNumber=$2&g2_fileName=$3 last;
rewrite ^/v/([^?]+)$ /main.php?g2_path=$1 last;
} #error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/local/www/nginx-dist;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}===== gallery.conf END ===== 改完 nginx 的設定之後,記得要重跑 nginx 才會生效: 先跑個一陣子觀察看看。 XD TrackbacksThe trackback URL for this entry is: http://idreamer.spaces.live.com/blog/cns!86AB72D5979C4135!861.trak Weblogs that reference this entry
|
|
|