Nginx Rewrite

Nginx的設定檔中,可以針對不同的目的端做流量導向,或者又可以稱作是rewrite... 也就是網址重新導向的動作,
設定上不難,原則上可以在server{...}中設定下面的判斷與rewrite語句即可:

if ($host ~* ^(example\.com|www\.example\.com)$ ){
  rewrite ^/(.*)$ https://example.com/$1 permanent;
}

或者可用:

rewrite ^ https://$server_name$request_uri? permanent;

範例:

    server {        listen      1.2.3.4:80 default;        server_name example.com www.example.com;        ## redirect http to https ##        rewrite        ^ https://$server_name$request_uri? permanent;  }

參考至:http://www.cyberciti.biz/faq/linux-unix-nginx-redirect-all-http-to-https/