connection limit

每一ip最多50連線數

1
2
3
4
5
6
7
8
9
limit_conn_zone $binary_remote_addr zone=connlimit:10m;
server {
# ...
location / {
limit_conn connlimit 50;
# ...
}
# ...
}

bandwith limit

當流量超過500k時限制速度為50k

1
2
3
4
5
6
7
8
9
10
limit_conn_zone $binary_remote_addr zone=connlimit:10m;
server {
# ...
location / {
limit_rate 50k;
limit_rate_after 500k;
# ...
}
}

rate limit

每秒最多50 request

1
2
3
4
5
6
7
8
9
10
limit_req_zone $binary_remote_addr zone=one:10m rate=50r/s;
server {
# ...
location / {
limit_req zone=one burst=5 nodelay;
# ...
}
# ...
}

Comment and share

production環境下需要設定rate limit來避免DOS攻擊
以下介紹兩種設定方式,一種是讓ap server來擋(這裡介紹nginx),一種是讓系統防火墻來擋(這裡介紹ufw)

Continue reading

Container之間有關係時可以用docker command中的–link搞定
當有多個Container需要連結時我們會希望能撰寫一份設定檔定義Container之間的關係然後執行就好
這就是docker-compose在做的事
撰寫docker-compose.yml定義各Container link relation
然後run docker-compose up -d

Command

1
docker-compose -f ./docker-compose.yml up -d

docker-compose.yml example

以下設定表示
faceblock是ap server
zombodb_postgres是postgres database
zombodb_elastic是elasticsearch database
faceblock相依於zombodb_postgres
zombodb_postgres相依於zombodb_elastic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
faceblock:
build: ./faceblock # DockerFile location
ports: # export ports
- "3001:3000"
- "3043:443"
links: # dependency
- zombodb_postgres
entrypoint: /execute.sh
zombodb_postgres:
build: ./postgres
ports:
- "5432:5432"
links:
- zombodb_elastic
restart: always # auto restart while exit
zombodb_elastic:
build: ./elasticsearch
ports:
- "9200:9200"
- "9300:9300"
restart: always

Comment and share

Create-React-App正常使用下無法更改babel設定
且為了保持產生的bundle.js不會太大
Create-React-App並不會將babel-polyfill全部打開
例如以下這些在IE中將會失敗的Function
Array.includes, String.includes, Object.values
以下簡單介紹3種解決辦法

Continue reading

Domain Setting

  1. 買一個domain(namecheap之類的)
  2. 照著官方文件做吧
    https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean

Swap Setting

Digital Ocean每月5美金的那個VPS,記憶體只有512MB
並且Digital Ocean預設OS的Swap是關閉的(官方說明SSD不建議使用swap)
若在上面再用docker的話高機率因為記憶體不足process被kill掉
若是真的不想加錢買更多記憶體的話還是可以手動開啟swap

一樣官方文件照著做就好
https://www.digitalocean.com/community/tutorials/how-to-add-swap-on-ubuntu-14-04

Comment and share

  • page 1 of 1

Cwza

Hello everyone.
I’m cwza.
Welcome to my blog.


Software Engineer


Taiwan/Taipei