2013年7月15日 星期一

2013年7月14日 星期日

[Nginx] 使用Nginx proxy_pass 時保留 host header

原本我使用 nginx 的 proxy_pass 只設定這樣

vim /usr/local/etc/nginx/site-enabled/site
server {
    listen 80;
    server_name my-domain-name.com;
 
    location / {
        proxy_pass  http://hank.local:8210;
    }
}

但是在後端程式從 header 裡判斷 host 會一直找到 hank.local:8210 而不是 my-domain-name.com

後來找到一個方法可以保留 header 到 proxy 裡, 加上 proxy_set_header Host $http_host 即可

server {
    listen 80;
    server_name my-domain-name.com;
 
    location / {
        proxy_pass  http://hank.local:8210;
        proxy_set_header Host $http_host;
    }
}

重新讀取 nginx 設定檔

sudo nginx -s reload

2013年7月8日 星期一

[Mac] 英文單字或句子不會唸? 讓Mac直接幫你念出來。

常看到一個英文單字或句子時, 不懂得怎麼唸, 秉持勤勉精神, 想努力學習一下, 但總是沒有很好的工具可以快速方便的唸出不懂怎麼唸的句子, 只要妳是用Mac, 內建就有功能能做到

突然發現Mac有個say指令, 可以直接在terminal底下唸出輸入的文字

say - Convert text to audible speech

直接在指令後面接上要說出的單字或句子

$ say Hello

或是指定說出一個檔案內的內容

$ say -f article.txt

也可以指定語音檔取代內建的語音, 或是使用其他內建的語音

$ say -v ?

看看更多的附加功能

$ man say 對於學習英文唸法時很有用 :)

2013年6月27日 星期四

2013年6月20日 星期四

[Quotes] Simple can be harder than complex ... Steve Jobs - 簡單比複雜難得多

"Simple can be harder than complex. You have to work hard to get your thinking clean to make it simple. But it’s worth it in the end because once you get there, you can move mountains." -- Steve Jobs

簡單比複雜難得多,你必須竭盡全力、理清思路,才能創造簡單。但這絕對值得,因為只有這樣,你才能開闢新世界。

2013年6月19日 星期三

[ssh] ProxyCommand - Run a local command before ssh to remote server.

Modify ~/.ssh/config
Host mydomain
    ProxyCommand sh -c "local_command /usr/bin/nc %h %p"

Host mydomain
    Hostname=mokoversity.com
    IdentityFile=~/.ssh/mokoversity_dsa
    User=hank
    PasswordAuthentication=no
    PubkeyAuthentication=yes

2013年6月18日 星期二

[Mac] ssh remote server through socks proxy - 經由socks proxy ssh到遠端Server

1. Install ProxyChains

$ wget https://gist.github.com/allenhuang/3792521/raw/bb52568695f9d745004eee87b892637f9d17a771/proxychains4_formula.rb
$ mv proxychains4_formula.rb /usr/local/Library/Formula/Proxychains.rb
$ brew install --HEAD proxychains

2. Modify ProxyChains conf

$ vim /usr/local/etc/proxychains.conf

set this line to conf:

socks4 127.0.0.1 8888

3. Open socks

ssh -vND 8888 user@socks.server

4. Settings Socks Proxy on Mac Network Preference

5. Connect to remote server

$ /usr/local/bin/proxychains4 ssh user@remote.server

2013年6月15日 星期六

[Vim] vim configuration

我其實很少用vim ... 不過有時候在Mac用一下、Linux用一下,覺得沒存一下設定檔不行... 所以慢慢整理一份出來

See Also

http://vim.wikia.com/wiki/Example_vimrc

2013年6月3日 星期一

F2E前端工程師面試問題集 - Front-end Job Interview Questions

Fork me on Github : Front-end-Developer-Interview-Questions

[OSX] dotfiles - zsh based Terminal editor and configuration files.

My dotfiles: https://github.com/hankwang/dotfiles

Image 1

Image 2

[OSX] copy last command by pbcopy - 複製上一個指令到剪貼簿

例如測試一行command是不是正確的, 確認之後我想複製起來做筆記或是貼到別地方, 這時候就可以透過pbcopy達到快速複製的效果, 不用再用滑鼠去框。

$ ps -awx

把上一個指令複製到剪貼簿

$ echo "!!" | pbcopy

把上一個指令的最後一個參數複製到剪貼簿

$ echo "!$" | pbcopy

2013年6月2日 星期日

[git] Syncing a fork - 同步原本repo的修改到fork出來的repo

  1. 加入新的遠端repo
  2. 取回遠端repo
  3. 合併repo到master
  4. 解決conflict的commits

列出目前的遠端repo

$ git remote -v 
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)

加入一個新的遠端repo

$ git remote add upstream https://github.com/otheruser/repo.git

註: upstream 為加入的遠端repo名稱, 可以自取


查看新加入的遠端repo

$ git remote -v

origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
upstream https://github.com/otheruser/repo.git (fetch)
upstream https://github.com/otheruser/repo.git (push)

取回新加入的遠端repo的所有分支(branches)

$ git fetch upstream

remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/otheruser/repo
 * [new branch]      master     -> upstream/master

查看目前本機和遠端的所有分支(branches)

$ git branch -va

* master                  a422352 My local commit
  remotes/origin/HEAD     -> origin/master
  remotes/origin/master   a422352 My local commit
  remotes/upstream/master 5fdff0f Some upstream commit

合併upstream的master到目前repo的master

$ git merge upstream/master

Updating 34e91da..16c56ad
Fast-forward
README.md                 |    5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

如果merge時遇到conflict, 例如README.md conflict

$ git status

# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Changes to be committed:
#
#   new file:   run.sh
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#   both modified:      README.md

編輯README.md處理conflict的地方後, 重新commit

$ git add README.md
$ git rebase --continue

See also

Github - Syncing a fork

2013年5月22日 星期三

[Python] list pip installed packages - 列出pip已安裝的套件

List all installed packages - 列出所有已安裝的套件

$ pip freeze

Check specify package version - 查看某套件版本

$ pip freeze | grep Django

2013年5月10日 星期五

2013年4月26日 星期五

2013年4月25日 星期四

[NodeJS] Auto deploy by github hook

Github hook service會在有新的commit的時候觸發hook API(bitbucket也有), 這可以用在

  • 遠端Server自動部署, 才不用每次都ssh到遠端Server去git pull然後deploy一遍
  • 自動發訊息到團隊的協作平台或是寄發Email
  • ...

Github本身支援很多好用的服務, 那我是用WebHook在我的主機上, 當有commit時會觸發Server上的hook, 然後執行一個Shell Script, 自動git pull然後重新啓動我的Web Service

$ cd /var/web/project
$ git pull
$ forever restart /var/web/project/app.js

Code
https://github.com/hankwang/node-github-hook-deploy


Related Posts Plugin for WordPress, Blogger...