1. 下載源碼編譯
https://nginx.org/download/nginx-1.13.4.tar.gz
2. 下載依賴模塊包
這里直接yum 安裝
yum ? install ? ?openssl ? openssl-devel
yum ? ?install ? pcre-devel
3. 安裝
可以直接默認(rèn) ?./configure
我是為了添加https 以及狀態(tài)監(jiān)測模塊纹份,還有四層負(fù)載均衡塞帐,比較好的地方是這個模塊是
直接內(nèi)置里面的竟块。
./configure--prefix=/usr/local/nginx–with-http_ssl_module–with-http_stub_status_module-with-stream
make&&makeinstall
4. ?使用
server{
listen80;
server_namelocalhost;
#charset koi8-r;
#access_log? logs/host.access.log? main;
location/{
mirror/mirror;# 可配置多個
mirror_request_bodyoff;
roothtml;
mirror/mirror2;
indexindex.htmlindex.htm;
}
# mirror配置
location/mirror{
proxy_passhttp://127.0.0.1:8080$request_uri;
proxy_pass_request_bodyoff;
proxy_set_headerContent-Length"";
proxy_set_headerX-Original-URI$request_uri;
}
location/mirror2{
proxy_passhttp://127.0.0.1:8081$request_uri;
proxy_pass_request_bodyoff;
proxy_set_headerContent-Length"";
proxy_set_headerX-Original-URI$request_uri;
}
error_page500502503504/50x.html;
location=/50x.html {
roothtml;
}
}
server{
listen8080;
server_namelocalhost;
location/{
roothtml2;
indexindex.htmlindex.htm;
}
}
server{
listen8081;
server_namelocalhost;
location/{
roothtml3;
indexindex.htmlindex.htm;
}
}
?
5. 啟動測試即可
/sbin/nginx-t
/sbin/nginx
6. 價值
流量拷貝只冻、以前的方案可能有tcpcopy ?openresty ?capture_multi 等等,
原生內(nèi)置了业汰,就是好用,希望openresty 也內(nèi)置進(jìn)去,配置capture_muilt 還是有
點(diǎn)不是很方便铜秆,如果結(jié)合起來,那就太強(qiáng)大了讶迁。
7. 待確認(rèn)
性能连茧,穩(wěn)定性,以及生產(chǎn)環(huán)境使用的坑巍糯。
8. 參考資料
https://nginx.org/en/docs/http/ngx_http_mirror_module.html