Nginx
nginx 是以 process 為主的模式,主要有一個 master 和 worker process,worker 數量跟 CPU 一樣才會最大化效能
nginx 是用 async non-blocking 模式,apache 則是用 async blocking,因此在非常高的併發量下,NGINX效能較好
工作原理是 worker 們會去搶一個鎖,搶到的就可以處理 request,因為是 async 所以處理後就可以解鎖,worker 們再去競爭
mime.types: https://my.oschina.net/plutonji/blog/527797
Forwarded proxy: server does not know who is the client, forward proxy proxy the client
Reverse proxy: Client does not know the server, reverse proxy proxy the servers.
to Log the real IP when using reverse proxy, need to proxy_set_header (https://reurl.cc/qmGgg\
代理、反向代理 https://www.zhihu.com/question/24723688
map string $var { ... } => value of $var depends on string.
lua_block => lua 語法
https://hackmd.io/nOYw9nz5QbKw11LWCxkiLQ?view
向服務器傳送檔案 nginx 作弊法:
向服務器傳檔案通常需要寫 server 端的 API,用 http POST 帶 multipart file
如果使用 nginx 的話,如以下:
location /upload1 {
limit_except POST { deny all; }
client_body_temp_path /tmp;
client_body_in_file_only on;
client_body_buffer_size 128K;
client_max_body_size 20G;
echo_read_request_body; #for debug
echo $request_body_file; #for debug
}
limit_except : 只限定 POST 方法
client_body_temp_path : 上傳文件的定址,這裡設定為 root/tmp
client_body_in_file_only :
首先要有個概念,nginx 有個請求緩衝區,在接收到请求时,nginx 将其写入这些缓冲区。 这些缓冲区中的数据可作为NGINX变量使用,例如$request_body。而 client_body_in_file_only 是禁止將請求寫到緩衝區,而是寫到一個文件,on 表示請求結束後不刪掉文件。之後可以透過 $request_body_file 來使用這個文件
這樣就可以將帶有 multipart 的請求先暫存到文件了,是一種可以快速取得上傳檔案的方法