2010年2月26日 星期五

Enable or fix logging for HAProxy load balancer

Enable or fix logging for HAProxy load balancer

On a RedHat/CentOS server, edit the value of SYSLOGD_OPTIONS in /etc/sysconfig/syslog:

SYSLOGD_OPTIONS=”-m 0 -r”


On a Debian/Ubuntu server, edit the value of SYSLOGD in /etc/default/syslogd:

SYSLOGD=”-r”


/etc/syslog.conf:

local0.* /var/log/haproxy.log


restart syslog service to apply changes:

service syslog restart

2010年2月22日 星期一

request host, query paramters, header

登入登出轉址設計

2010年2月21日 星期日

multi-step

RoR Multi-step forms

2010年2月8日 星期一

render outside your controller

Rails: Calling render() outside your Controllers
Calling Rails Render Partial in a Model or Background Task


2010年2月7日 星期日

Turning web server configuration

Setting Static Asset Expires Headers with nginx and Passenger

Nginx
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
expires max;
break;
}

2010年2月4日 星期四

redirect permanent

Permanent Redirect with HTTP 301

#Apache
RewriteCond %{HTTP_HOST} 17\.ooxx\.com [NC]
RewriteRule ^/(.*) http://17.ooxx.com.tw/$1 [L,R=permanent]

#Nginx
if ($host ~* ^17.ooxx\.com) {
rewrite ^/(.*) http://17.ooxx.com.tw/$1 permanent;
}

2010年2月3日 星期三

META HTTP-EQUIV="refresh" 實現網頁自動跳轉

META HTTP-EQUIV="refresh" 實現網頁自動跳轉

2010年2月2日 星期二

rails default environment

~/.bashrc

export PATH=$PATH:/opt/ruby-enterprise/bin
export RAILS_ENV=production

nginx memo

Nginx泛域名解析及Rewrite重定向普通頁面及帶參數的頁面
Nginx "how to" - Fast and Secure Web Server
Nginx Location



靜態地址重定向到帶參數的動態地址
rewrite "^(.*)/service/(.*)\.html$" $1/service.php?sid=$2 permanent;


帶參數的動態地址重定向到靜態地址
if ($query_string ~* id=(.*)) {
set $id $1;
rewrite "^(.*)/article.asp$" $1/article/$id.htm last;
}


舉例:
abc.domian.com/sort/2 => abc.domian.com/index.php?act=sort&name=abc&id=2

if ($host ~* (.*)\.domain\.com) {
set $sub_name $1;
rewrite ^/sort\/(\d+)\/?$ /index.php?act=sort&cid=$sub_name&id=$1 last;
}


Nginx Rewrite Flags
* last 相當於Apache裡的[L]標記,表示完成rewrite
* break 終止匹配, 不再匹配後面的規則
* redirect 返回302臨時重定向
* permanent 返回301永久重定向

Nginx正則表達式匹配
* ~ 為區分大小寫匹配
* ~* 為不區分大小寫匹配
* !~和!~*分別為區分大小寫不匹配及不區分大小寫不匹配

Nginx文件及目錄匹配
* -f和!-f用來判斷是否存在文件
* -d和!-d用來判斷是否存在目錄
* -e和!-e用來判斷是否存在文件或目錄
* -x和!-x用來判斷文件是否可執行

Nginx全局變量
$args
$content_length
$content_type
$document_root
$document_uri
$host
$http_user_agent
$http_cookie
$limit_rate
$request_body_file
$request_method
$remote_addr
$remote_port
$remote_user
$request_filename
$request_uri
$query_string
$scheme
$server_protocol
$server_addr
$server_name
$server_port
$uri

2010年2月1日 星期一

restart nginx

 
alias startnginx='sudo /opt/nginx/sbin/nginx'
alias stopnginx='sudo kill `cat /opt/nginx/logs/nginx.pid `'
alias restartnginx='stopnginx; startnginx'

transcation

Transaction in Rails
Working with transactions in Rails