MockServer工具-Moco應(yīng)用
前言
前段時間介紹了Mock基本知識和Moco工具簡單使用,今天重點介紹小編在實際業(yè)務(wù)所遇到的Moco應(yīng)用場景。
Nginx代理
1.將域名轉(zhuǎn)發(fā)到本地端口
將域名轉(zhuǎn)發(fā)到本地另一個端口上
server{listen 80;server_name sogou.com;index index.php index.html index.htm;location / {proxy_pass http://127.0.0.1:8080; # 轉(zhuǎn)發(fā)規(guī)則proxy_set_header Host $proxy_host; # 修改轉(zhuǎn)發(fā)請求頭,讓8080端口的應(yīng)用可以受到真實的請求proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
訪問http://sogou.com時 就會轉(zhuǎn)發(fā)到本地8080端口
2.將域名轉(zhuǎn)發(fā)到另一個域名
server{listen 80;server_name sogou.com;index index.php index.html index.htm;location / {proxy_pass http://www.sogou.com;proxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
3.本地一個端口轉(zhuǎn)發(fā)到另一個端口或另一個域名
server{listen 80;server_name 127.0.0.1; # 公網(wǎng)ipindex index.php index.html index.htm;location / {proxy_pass http://127.0.0.1:8080; # 或 http://www.sogou.comproxy_set_header Host $proxy_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}
訪問http://127.0.0.1?就會轉(zhuǎn)發(fā)本地8080端口或者訪問http://www.sogou.com
4.加/ 與不加/
在配置proxy_pass代理轉(zhuǎn)發(fā)時,如果后面的url加/,表示絕對根路徑;如果沒有/,表示相對路徑
1. 加 /
server_name?sogou.comlocation /data/ {proxy_pass http://127.0.0.1/;}
訪問http://sogou.com/data/index.html?會轉(zhuǎn)發(fā)到?http://127.0.0.1/index.html
2.不加/
server_name?sogou.comlocation /data/ {proxy_pass http://127.0.0.1;}
訪問?http://sogou.com/data/index.html?會轉(zhuǎn)發(fā)到?http://127.0.0.1/data/index.html
Moco部署
1.確定DSP請求方式、請求頭部、Response
例如:
response.json
[{"description": "pinYinAdx","request":{"method": "get","headers": {"content-type": "application/json"}},"response": {"file": "pinYin.response"}}]
pinYin.response
{??"id":?"51f7eef525d66c11f0e53b12eacd6a8a",? ?...}
2.部署并啟動Moco
通過https://github.com/dreamhead/moco?獲取moco jar包
后臺運行Moco服務(wù)
nohup?java?-jar?moco-runner-1.1.0-standalone.jar?http?-p?4000?-c?response.json??&
業(yè)務(wù)應(yīng)用
1.nginx.conf配置
server {?????server_name?sogou.dsp.ipinyinu.com;location /sogou {proxy_pass http://10.168.15.1:4000; }location / {?????????????????proxy_pass?http://10.168.15.3:4000;????????????}}
2.配置目標(biāo)機(jī)器Host
10.168.15.1?sogou.dsp.ipinyou.com?
3. 當(dāng)請求域名為sogou.dsp.ipinyin.com ,且uri 包含/sogou,轉(zhuǎn)發(fā)到已經(jīng)部署好的MockServer
文章合集
Selenium?|?Appium??|?Jenkins??|??Jmeter?
軟件測試方法匯總?|?Postman接口參數(shù)化?|?測試用例設(shè)計?|?App抓包
視頻教程
Selenium?|?Appium?|?Jenkins?|?Jmeter
AWS與Docker
如何使用AWS EC2+Docker+JMeter構(gòu)建分布式負(fù)載測試基礎(chǔ)架構(gòu)
Docker容器數(shù)據(jù)持久化和容器網(wǎng)橋連接
Docker刪除image和container
Docker與VM虛擬機(jī)的區(qū)別以及Docker的特點
END
覺得不錯,可以“點贊”和“在看”,或者轉(zhuǎn)發(fā)、留言
精彩的內(nèi)容要和朋友分享哦
微信群:
軟件自動化測試交流群已創(chuàng)建,公號回復(fù)入群即可獲取入群二維碼。
