用途
1.性能測試過程中使用到第三方服務(wù)時,可用nginx替代征冷,先對模擬的服務(wù)進(jìn)行壓測饿这,給出數(shù)據(jù)來說明模擬的服務(wù)器對本次業(yè)務(wù)性能測試影響較小噪珊。
2.功能測試過程中模擬第三方服務(wù)異常情況,或者更多種正常情況饰豺,驗證被測系統(tǒng)的異常處理亿鲜。
nginx安裝(Linux)
1)下載tar包放在/usr/local下面下載地址:http://nginx.org/en/download.html
2)安裝相關(guān)依賴和庫文件
# yum -y install gcc gcc-c++ autoconf automake//gcc、gcc-c++的庫文件
# yum -y install pcre pcre-devel//安裝Nginx依賴包
# yum -y install zlib zlib-devel
解壓nginx.tar.gz包
# tar -zxvf /home/veryyoung/nginx-1.12.0.tar.gz//解壓tar包
在解壓包中運(yùn)行./configure并安裝
# cd /home/veryyoung/nginx-1.12.0/
# ./configure? //確認(rèn)執(zhí)行之前有執(zhí)行權(quán)限冤吨,沒有的話執(zhí)行命令? chmod 777 configure
# make
# make install? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //安裝
為nginx擴(kuò)展echo(nginx本身不帶echo的蒿柳,必須自己下載)
從地址https://github.com/openresty/echo-nginx-module下載echo-nginx-module
下載之后安裝按照普通模塊安裝即可:
./configure --prefix=/usr/local/nginx --add-module=/dir-to-echo-nginx-module? //執(zhí)行的時候還是去nginx解壓的地方,后者的dir-to-echo-nginx-module路徑是下載的echo擴(kuò)展解壓所在的目錄(我是在/home/veryyoung/echo-nginx-module-master)
安裝之后漩蟆,root權(quán)限執(zhí)行:
make -j2 && make install
然后就可以在自定義模塊中使用echo指令垒探。
比如在配置文件nginx.conf中添加:
location /veryyoung{
echo '{"name":"veryyoung"}';
}
還可以修改返回類型:
將 default_type? application/octet-stream;? 修改為? default_type? application/json;? //返回json類型
在nginx.conf文件中可添加多個location:
location /test {
echo '{"msg":"hello world!"}';
}
更多的nginx配置信息請看另一文:nginx之nginx.conf文件