2015年9月30日 星期三

解決cygwin 的screen排版bug

某次cygwin裝了cron後
使用screen 在某個tty後一直按enter,或tail -f error_log時,
超過螢幕高度時會把shelltittle吃掉 產生畫面的bug
原因:
開著cygwin的screen用GUI安裝東西就會產生此錯誤,我開著裝php5-jsonc 時出錯的

解法:
用cygwin安裝的GUI 把php5-jsonc移除
用cygwin安裝的GUI 把screen移除(注意:Uninstall無效)
重開機
等一下
用cygwin安裝的GUI 安裝screen
失敗再重新做一次
$ screen (第一次我沒用-U)
正常使用

最後還是用apt-cyg來安裝 php-json
$ apt-cyg install php-json
Installing php-json
--2015-09-30 19:02:27--  http://ftp.cse.yzu.edu.tw/pub/cygwin//x86_64/release/php-jsonc/php-json/php-json-1.3.7-1.tar.xz
Resolving ftp.cse.yzu.edu.tw (ftp.cse.yzu.edu.tw)... 140.138.144.170
Connecting to ftp.cse.yzu.edu.tw (ftp.cse.yzu.edu.tw)|140.138.144.170|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 32 [application/octet-stream]
Saving to: ‘php-json-1.3.7-1.tar.xz’

php-json-1.3.7-1.tar.xz         100%[=======================================================>]      32  --.-KB/s   in 0s

2015-09-30 19:02:27 (207 KB/s) - ‘php-json-1.3.7-1.tar.xz’ saved [32/32]

php-json-1.3.7-1.tar.xz: OK
Unpacking...
Package php-json requires the following packages, installing:
php-jsonc
Installing php-jsonc
php-jsonc-1.3.7-1.tar.xz: OK
Unpacking...
Package php-jsonc requires the following packages, installing:
libjson-c2 php
Package libjson-c2 is already installed, skipping
Package php is already installed, skipping
Package php-json installed
$ php -i | grep json
Additional .ini files parsed => /etc/php5/conf.d/json.ini,
json
json support => enabled
json version => 1.3.7



2015年9月28日 星期一

Windows 跑 例行性工作排程

在windows7工作環境中,我還是習慣使用cygwin這種unix like的命令行來工作
如何在cygwin使用工作排程呢?

方法一 、使用cron-config安裝(失敗)
1. 透過cygwin 的GUI安裝cron (Vixie Cron) => cygrunsrv已安裝
2. cygwin:設定cron-config
$ cron-config
running as yourself? => 選no
3. 編輯cron file
$ crontab -e
4. 使用 $cygrunsrv -S-E 來手動開關 cron 服務
$ cygrunsrv -S cron # 開啟
$ cygrunsrv -E cron # 關閉

方法二、使用cygrunsrv將cron安裝成一個windows的服務(失敗)
$ cygrunsrv -I cron -p /usr/sbin/cron -a -D
$ net start cron
與方法一會衝突、用其中一個啟動另外一個方法會開/關不了

使用方法一和方法二cronjob雖然每分鐘會嘗試執行,但是不會正確執行
$ cronevents # 檢查cronjob執行狀態
2015/09/25 11:48:01 [SYSTEM] /usr/sbin/cron: PID 87772: (user) CMD (/usr/bin/bash /home/user/test.sh > /dev/null 2>&1)
2015/09/25 11:48:01 [SYSTEM] /usr/sbin/cron: PID 87772: (CRON) error (can't switch user context)
在crontab -e 中把執行使用者改成cygrunsrv依然不行
* * * * * cygrunsrv /usr/bin/bash /home/user/test.sh
(放棄)

方法三、使用windows 7 原生的"工作排程器"
使用[工作排程器],請依序按一下 [開始] 按鈕、[控制台]、[系統及安全性] 及 [系統管理工具],然後按兩下 [工作排程器]
點右邊"動作"=> "建立工作" 加入
填寫
一般 => 名稱
觸發程序 => 新增 => 勾選"重複工作每隔" => 選"5 分鐘"後手動改 "1分鐘" (和Linux crontab一樣最少是一分鐘) => 持續時間:不限制
動作 => 新增 => 程式或指令碼 =>
C:\cygwin64\bin\bash.exe -l -c "/home/user/test.sh"

建立後點左邊 =>工作排程器程式庫 => 可以找到你剛剛新增的工作,然後啟用/停用

參考資料:
http://stackoverflow.com/questions/707184/how-do-you-run-a-crontab-in-cygwin-on-windows How do you run a crontab in Cygwin on Windows?
http://yuanann.pixnet.net/blog/post/13512677-cygwin-%E5%AE%89%E8%A3%9Dcrontab-%E6%AD%A5%E9%A9%9F  cygwin 安裝crontab 步驟 (失敗)
http://www.7tutorials.com/advanced-users-task-creation-task-scheduler How to Create Advanced Tasks with the Task Scheduler




2015年9月22日 星期二

修復MySQL的基數(Cardinality)

看到了這句SQL:
SELECT DISTINCT(`issue`) FROM `table_name` FORCE INDEX (`idx_issue`) 
WHERE `issue` <= '2015014'
FORCE INDEX => 強制索引
代表該語句只使用索引名稱為idx_issue 的索引,延伸的用法有 IGNORE INDEX

什麼是基數( Cardinality )
基數是數據列所包含的不同值的數量。例如,某個數據列包含值1、3、7、4、7、3,那麼它的基數就是4。索引的基數相對於數據表行數較高(也就是說,列中包含很多不同的值,重複的值很少)的時候,它的工作效果最好。如果某數據列含有很多不同的年齡,索引會很快地分辨數據行。如果某個數據列用於記錄性別(只有"M"和"F"兩種值),那麼索引的用處就不大。如果值出現的幾率幾乎相等,那麼無論搜索哪個值都可能得到一半的數據行。在這些情況下,最好根本不要使用索引,因為查詢優化器發現某個值出現在表的數據行中的百分比很高的時候,它一般會忽略索引,進行全表掃描。慣用的百分比界線是"30%"。

查詢基數
mysql> show index from table_name

查詢到的基數與表中資料不符
修復指令
mysql> ANALYZE TABLE table_name

參考資料:
http://bbs.csdn.net/topics/80230813 请问MYSQL数据库中建立索引,索引的基数是什么意思?
https://et3w503.wordpress.com/2008/12/02/%E9%80%9A%E9%81%8Eforce-index%E4%BA%86%E8%A7%A3%E7%9A%84mysql%E6%9F%A5%E8%A9%A2%E7%9A%84%E6%80%A7%E8%83%BD%E5%84%AA%E5%8C%96/  通過force index了解的MySQL查詢的性能優化
http://blog.csdn.net/alongken2005/article/details/6394016  mysql优化Analyze Table


2015年9月15日 星期二

PHP 的 register_shutdown_function 函數


功能:
register_shutdown_function() 函數可實現當程式執行完成後執行的函數,其功能為可實現程式執行完成的後續操作。程式在運行的時候可能存在執行超時,或強制關閉等情況,但這種情況下默認的提示是非常不友好的,如果使用register_shutdown_function()函數捕獲異常,就能提供更加友好的錯誤展示方式,同時可以實現一些功能的後續操作,如執行完成後的臨時數據清理,包括臨時檔等。

可以這樣理解調用條件:
1、當頁面被用戶強制停止時
2、當程式代碼運行超時時
3、當PHP代碼執行完成時,代碼執行存在異常和錯誤、警告

實例:
class ClassDemo {
 public function __construct() {
  register_shutdown_function(array($this, "f"), array('bear'=>123, 'ted'=>'test'));
 }

 public function f($param) {
  echo "
f() \$param:";
  print_r($param);
  echo "
"; } public function g($param){ echo "
g() \$param:";
  print_r($param);
  echo "
"; } public function h($param){ echo "
h() \$param:";
  print_r($param);
  echo "
"; } } $demo = new ClassDemo(); register_shutdown_function(array($demo, "g"), array('bear'=>456, 'ted'=>'test2')); // register_shutdown_function()函數可重複調用,但執行的順序與註冊的順序相同 echo "before "; exit; register_shutdown_function(array($demo, "h"), array('bear'=>789, 'ted'=>'test3')); // 如果在調用register_shutdown_function()函數之前有exit()函數調用,register_shutdown_function()函數將不能執行 echo " after";
輸出:
before

f() $param:Array
(
    [bear] => 123
    [ted] => test
)

g() $param:Array
(
    [bear] => 456
    [ted] => test2
)
s

注意事項
1,register_shutdown_function()函數可重複調用,但執行的順序與註冊的順序相同
2,如果在調用register_shutdown_function()函數之前有exit()函數調用,register_shutdown_function()函數將不能執行
3,PHP4後支持註冊函數參數傳遞
4,在某些服務端,如Apache,當前目錄在register_shutdown_function()函數中能夠改變
5,register_shutdown_function()函數執行在headers發送之後

應用
來記錄php的輸出日誌


參考資料:
http://my.oschina.net/jiuxiaoyao/blog/78558 利用php的register_shutdown_function来记录php的输出日志
http://yanue.net/post-99.html register_shutdown_function 函数详解

2015年9月3日 星期四

PHP 獲取資料夾下特定檔案的檔名

假設資料夾下有這些東西,folder是資料夾
$ ls
folder  handlebars-v3.0.3.js  jquery-1.10.2.min.js  start.html

要抓取所有的js檔的檔名

使用 opendir()
$ php -r '$handle=opendir("./"); while(false!==($file=readdir($handle))){ echo $file."\n"; } closedir($handle);'
.
..
folder
handlebars-v3.0.3.js
jquery-1.10.2.min.js
start.html
相當麻煩,必須先opendir(),用完後還要closedir()。取出的過程還需要跑回圈做處理


使用scandir()
$ php -r '$files = scandir("./"); print_r($files);'
Array
(
    [0] => .
    [1] => ..
    [2] => folder
    [3] => handlebars-v3.0.3.js
    [4] => jquery-1.10.2.min.js
    [5] => start.html
)
直接取出,只能取出後再對檔案過濾,連資料夾也會一起取出

使用glob()  =>採用
$ php -r '$files = glob("*{.js}", GLOB_BRACE); print_r($files);'
Array
(
    [0] => handlebars-v3.0.3.js
    [1] => jquery-1.10.2.min.js
)
可以使用正規表示式過濾檔名


參考資料:
http://jishus.org/?p=690  【PHP】透過glob、scandir、readdir取得資料夾內的檔案列表


MySQL FIND_IN_SET()使用心得

前言:
原本只是想用一下FIND_IN_SET()這函數而想的題目,沒想到越變越複雜

目標:
有兩個表article和article_type,搜尋出所有種類為hot的文章,用article_type.id去搜尋,並把他所有種類描述列出來

資料庫:
mysql> select * from article;
+----+----------+-------+---------+
| id | type_set | title | content |
+----+----------+-------+---------+
|  1 | 1,2,4    | test1 | test1   |
|  2 | 2,4      | test2 | test2   |
|  3 | 2        | test3 | test3   |
+----+----------+-------+---------+

mysql> select * from article_type;
+----+---------------+
| id | description   |
+----+---------------+
|  1 | headline      |
|  2 | hot           |
|  3 | recommend     |
|  4 | international |
+----+---------------+

例:article.id = 1時, type_set=1,2,4 ,多一個欄位description_set = headline,hot,international

提示:
使用子查詢

解法:
mysql> SELECT article.*,
( SELECT GROUP_CONCAT(description SEPARATOR ",") FROM `article_type` WHERE FIND_IN_SET(id,type_set) ) AS description_set
FROM `article`,
     article_type
WHERE article_type.id IN(article.type_set)
  AND FIND_IN_SET('2',article.type_set);
+----+----------+-------+---------+----------------------------+
| id | type_set | title | content | description_set            |
+----+----------+-------+---------+----------------------------+
|  1 | 1,2,4    | test1 | test1   | headline,hot,international |
|  2 | 2,4      | test2 | test2   | hot,international          |
|  3 | 2        | test3 | test3   | hot                        |
+----+----------+-------+---------+----------------------------+

喇叭王:設計資料庫 ,不會把1,2,4 放到欄位裡面,再開個table做relation可能會比較好。 => 同意

sqlfiddle.com模擬結果:
http://sqlfiddle.com/#!9/a0117/89/0

資料庫SQL:
CREATE TABLE IF NOT EXISTS `article` (
  `id` int(11) NOT NULL,
  `type_set` varchar(255) NOT NULL,
  `title` varchar(255) NOT NULL,
  `content` text NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

INSERT INTO `article` (`id`, `type_set`, `title`, `content`) VALUES
(1, '1,2,4', 'test1', 'test1'),
(2, '2,4', 'test2', 'test2'),
(3, '2', 'test3', 'test3');

CREATE TABLE IF NOT EXISTS `article_type` (
  `id` int(11) NOT NULL,
  `description` varchar(255) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

INSERT INTO `article_type` (`id`, `description`) VALUES
(1, 'headline'),
(2, 'hot'),
(3, 'recommend'),
(4, 'international');

ALTER TABLE `article`
  ADD PRIMARY KEY (`id`);

ALTER TABLE `article_type`
  ADD PRIMARY KEY (`id`);


總結:
所以如果list是常量,則可以直接用IN, 否則要用find_in_set()函數。

參考資料:
http://www.111cn.net/database/mysql/50190.htm mysql数据库中find_in_set()和in()用法区别


2015年9月2日 星期三

好用的PHP套件

pinyin
網址: https://github.com/overtrue/pinyin
demo: http://overtrue.me/pinyin/
功用: 讓漢字轉成拼音
注意事項: 使用composer安裝。破音字無法轉,如:"重"慶、"重"量。最後不採用

大陸身份证号验证(兼容15,18位)
http://www.thinkphp.cn/code/343.html



PHP的Null、False和0比較

e-satis:
Null means "nothing". The var has not been initialized.
Null 意思是nothing。這個變數還沒被初始化。
False means "not true in a boolean context". Used to explicitly show you are dealing with logical issues.
False意思是"在boolean中不是true"。用於明確表明你正在處理的邏輯問題。
0 is an int. Nothing to do with the rest above, used for mathematics.
0是數字。與上面無關,用於數學。

gcb:
you pretty much have to always test for ===null or ===false, depending on the function. or for both, in cases such as filter_input()/filter_var()
你最好使用 === null 或 === false 去測試他。
一些測試:
var_dump( null < -1 ); #bool(true)
var_dump( null < 0 ); #bool(false)
var_dump( null < 1 ); #bool(true)

Comparisons of $x with PHP functions

Loose comparisons with ==

Strict comparisons with ===

圈紅處在 loose comparisions == 中為true




參考資料:
http://stackoverflow.com/questions/137487/null-vs-false-vs-0-in-php Null vs. False vs. 0 in PHP
http://www.seayee.net/article/info_115.html 讓 空字符串、0、null和 strval()、intval()、empty()、is_numeric()、is_string() 之間的關係
http://php.net/manual/en/types.comparisons.php PHP type comparison tables


好用的jQuery 套件

jQuery Tree
網址: https://github.com/daredevel/jquery-tree
demo: http://htmlpreview.github.io/?https://github.com/daredevel/jquery-tree/blob/master/index.html
功用: 智能勾選上下級的checkbox
注意事項: 只能在ul 和li 標籤使用, div 排版無效

jquery-clearsearch
網址: https://github.com/waslos/jquery-clearsearch
demo: http://jsfiddle.net/wldaunfr/FERw3/
功用: 讓input可以有"X"按鈕清除內容

jquery.zeroclipboard
網址: https://github.com/zeroclipboard/jquery.zeroclipboard
demo: http://zeroclipboard.org/#demo (非 jquery.zeroclipboard )
功用: (使用flash)複製文字
說明:
設定swf檔路徑
$.event.special.copy.options.swfPath = '/a/path/to/zeroclipboard/dist/ZeroClipboard.swf';
http://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript?page=1&tab=votes#tab-top
Automatic copying to clipboard may be dangerous, therefore most browsers (except IE) make it very difficult.
自動複製文字到剪貼簿可能是危險的,因此大部分瀏覽器(除了IE)不讓你輕易複製

jquery-zclip(未測)
網址: https://github.com/patricklodder/jquery-zclip
功用: (使用flash)複製文字
說明:
設定swf檔路徑
ZeroClipboard.config({swfPath: '/a/path/to/zeroclipboard/dist/ZeroClipboard.swf'});

dropload
網址:https://github.com/ximan/dropload
公用:移動端下拉刷新、上拉加載
說明:
無更多資料 -
loadDownFn : function(me){} 中ajax success寫
me.noData();
dropload.resetload();
在.lists加載資料,.lists的高度不設,.inner的高度(從header下開始)要設到手機瀏覽器的底部(前端亂切版css調不出來時只好用js直接調高度),.inner要設 overflow-y: scroll; 拖到底部時才能向下加載
<div class="inner">
  <div class="lists"></div>
</div>







haproxy使用心得

系統:ubuntu14.04

安裝:
$ sudo apt-get install haproxy

檢查haproxy版本
$ haproxy -v

檢查haproxy設定檔 ( /etc/haproxy/haproxy.cfg )
$ haproxy -V -c -f haproxy.cfg

設定:
1. 編輯 /etc/default/haproxy ,將 ENABLED=0 改為 1
ENABLED=0 => ENABLED=1

2. 避免 [ALERT] 243/175711 (2715) : Starting proxy http_proxy: cannot bind socket 錯誤
# sysctl -e net.ipv4.ip_nonlocal_bind=1

3. 解決 [ALERT] 243/175711 (2715) : Starting proxy http_proxy: cannot bind socket 錯誤
原來是nginx把 80 port 佔用了,要把nginx 換成其他port
把 /etc/nginx/sites-available 中vhost設定檔中server{}中的 listen 換成其他port
ex.
listen 80; => listen 81;
listen [::]:80; => listen [::]:81;
然後重啟nginx

4. 編輯haproxy.cfg (因為我的haproxy版本是1.4,所以照 http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#2.3 上面改的)
global
    daemon
    maxconn 256

defaults
    mode http
    timeout connect 5000ms
    timeout client 50000ms
    timeout server 50000ms

frontend http-in
    bind *:80
    default_backend servers2

frontend http-in2
    bind *:88
    default_backend servers

backend servers
    server server1 192.168.1.140:80 maxconn 32
backend servers2
    server server2 192.168.1.147:81 maxconn 32

架構
我的VM( 192.168.1.147 ):
haproxy 80
nginx  81

我電腦(win 7, 192.168.1.140):
apache 80

結果
http://192.168.1.147:88/ 開windows apache 80 程式
http://192.168.1.147/ 開VM nginx 81 程式

http://192.168.1.147:81/ 開VM nginx 81 程式

註:
如果只設一組 frontend 兩組backend
frontend http-in
    bind *:80
    default_backend servers

backend servers
    server server1 192.168.1.140:80 maxconn 32
    server server2 192.168.1.147:81 maxconn 32
這樣打開 http://192.168.1.147 在firefox用 ctrl+f5 刷頁,會在 192.168.1.140:80 和 192.168.1.147:81 兩台主機切換



參考資料:
http://blog.longwin.com.tw/2009/03/haproxy-ha-load-balance-2009/  使用 HAProxy 完成 網站分流, 平衡負載
http://cbonte.github.io/haproxy-dconv/configuration-1.4.html#2.3  HAProxy Configuration Manual ( 1.4 example )



2015年9月1日 星期二

mv, rm, touch 更動特殊名稱檔案( mv 減減 )

新增檔名 "--bear"的檔案
直接touch會報錯
$ touch --bear
touch: unrecognized option '--bear'
Try 'touch --help' for more information.
應使用
$ touch -- --bear

移動檔名"--bear"的檔案
直接mv會報錯
$ mv --bear __bear
mv: unrecognized option '--bear'
Try 'mv --help' for more information.
應使用
$ mv -- --bear __bear

刪除檔名"--bear"的檔案
直接rm會報錯
$ rm --bear
rm: unrecognized option '--bear'
Try 'rm ./--bear' to remove the file ‘--bear’.
Try 'rm --help' for more information.
應使用
$ rm -- --bear


參考資料:
http://superuser.com/questions/361573/mv-command-confuses-directory-name-with-command-option  mv command confuses directory name with command option


nginx vhost配置

系統:ubuntu 14.04

1. 建立資料夾
# mkdir /var/www/html/test.vm  # 程式資料夾
# mkdir /var/www/html/test.vm/logs # log資料夾

# chmod 755 -R /var/www/html/test.vm
# chown www-data:www-data -R /var/www/html/test.vm  # 我沒做,依然用bear:bear

2. 建立設定檔
# touch /etc/nginx/sites-available/test.vm
編輯設定檔test.vm內容:
server {
    listen 80;
    listen [::]:80;

    root /var/www/html/test.vm;  # 設定你程式的路徑
    index index.html index.htm; 

    server_name test.vm; # 虛擬主機的完整名稱

    location / {
        try_files $uri $uri/ =404;
    }

    access_log /var/www/html/test.vm/logs/access.log; # access_log 的位置
    error_log /var/www/html/test.vm/logs/error.log;
}

3. 啟用虛擬主機
nginx沒有像Apache 有a2ensite的指令來啟用虛擬主機,所以要用ln 去做
# ln -s /etc/nginx/sites-available/test.vm /etc/nginx/sites-enabled/test.vm

4. 重新啟動nginx
# service nginx restart

5. php頁面打不開(連結變成下載php檔案)
在你的test.vm加入下面這一段
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ .php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        include        fastcgi_params;
}

完整的test.vm檔:
server {
    listen 80;
    listen [::]:80;

    root /var/www/html/test.vm;
    index index.html index.htm;

    server_name test.vm;

    location / {
        try_files $uri $uri/ =404;
    }
    location ~ .php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_index  index.php;
        include        fastcgi_params;
    }

    access_log /var/www/html/test.vm/logs/access.log;
    error_log /var/www/html/test.vm/logs/error.log;

}

5.2 Nginx $document_root$fastcgi_script_name 與 $request_filename 的區別
http://serverfault.com/questions/465607/nginx-document-rootfastcgi-script-name-vs-request-filename  Nginx $document_root$fastcgi_script_name vs $request_filename
http://serverfault.com/questions/502776/what-is-the-correct-setting-of-nginxs-fastcgi-param-script-filename  What is the correct setting of Nginx's fastcgi_param SCRIPT_FILENAME?
$request_filename
This variable is equal to path to the file for the current request, formed from directives root or alias and URI request;
這個變數等於當前請求檔案的路徑,從指向的根或alias和URI請求所形成
$document_root
This variable is equal to the value of directive root for the current request;
這個變數等於當前請求的指向的根
$fastcgi_script_name
This variable is equal to the URI request or, if if the URI concludes with a forward slash, then the URI request plus the name of the index file given by fastcgi_index. It is possible to use this variable in place of both SCRIPT_FILENAME and PATH_TRANSLATED, utilized, in particular, for determining the name of the script in PHP.
這個變數等於URI請求,如果URI的結尾是斜線( ex. http:xxx/xx/ ),則該URI請求會加上fastcgi_index所設的索引名字。
$request_filename is just a nicer way of writing it.
$request_filename 只是更好的寫法

6.1 將入口檔改為a.do( 其內容一樣是php )
index 新增 a.do
index index.html index.htm a.do;
在 location / {} 中加入這段
location ~ .*\.(do|php)?$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_param  SCRIPT_FILENAME  /your_a.do_path/$fastcgi_script_name;
    include        fastcgi_params;
}

6.1.1 (AWS nginx編譯安裝)出現錯誤:
2016/xx/xx XX:XX:XX [error] 8866#0: *41 open() "/root/project/test.html" failed (13: Permission denied), client: x.x.x.x, server: user.domain.net, request: "GET /test.html HTTP/1.1", host: "user.domain.net"
原因,nginx編譯安裝只能把程式放在 安裝的路徑下 /usr/local/webserver/nginx/html/ 

6.1.2 出現錯誤:
2016/xx/xx XX:XX:XX [error] 8924#0: *42 FastCGI sent in stderr: "Access to the script '/usr/local/webserver/nginx/html/project/a.do' has been denied (see security.limit_extensions)" while reading response header from upstream, client: 1
6.1.2.2 出現錯誤:(CentOS 7)
頁面顯示 Access Denied.
access log 有記錄,error log 無記錄,一樣用下面的解法解。security.limit_extensions那行註解記得拿掉
解法:
http://stackoverflow.com/questions/23390531/access-denied-403-for-php-files-with-nginx-php-fpm
php-fpm的 /etc/php-fpm.d/www.confsecurity.limit_extensions新增.do
security.limit_extensions = .php .php3 .php4 .php5 .do

6.2 如果網頁伺服器是Apache2, 使a.do可以視為php網頁訪問
http://stackoverflow.com/questions/3555681/why-are-my-php-files-showing-as-plain-text
apache/conf/httpd.conf
修改 <IfModule mime_module> 中的
AddType application/x-httpd-php .php => AddType application/x-httpd-php .php .do

7. 設定url rewrite
在 location / {} 中加入這段
rewrite ^/(.+)-(.+).html$ /a.do?controller=$1&action=$2 last;

7.2 apache2
http://stackoverflow.com/questions/13867543/htaccess-rewrite-shtml-and-html-as-php
在網頁根目錄加入.htaccess,內容為
RewriteEngine On
RewriteRule ^(.+)_(.+)\.shtml$ /a.do?controllers=$1&actions=$2 [L,QSA]

8. 設定alias 資料夾
在 server {} 中加入
location /phpmyadmin {
    alias /var/www/phpmyadmin/$1;
}
這樣 http://your_domain/phpmyadmin 就能直接訪問 /var/www/phpmyadmin/ 的phpmyadmin

9. 設定多個網址指到同一隻程式(同Apache的ServerAlias)
在server {} 中的server_name加入
server_name test.vm m.test.vm; # 虛擬主機的完整名稱

參考資料:
http://www.arthurtoday.com/2010/09/ubuntu-nginx-virtual-host.html Ubuntu 設定 Nginx 虛擬主機 ( Virtual Host )
http://stackoverflow.com/questions/5687938/nginx-trouble-loading-index-file nginx trouble loading index file