nginx 跳轉(zhuǎn)指定接口
場景:
進行stub測試時,程序訪問的不是真正的接口,而是stub接口(提供假數(shù)據(jù)).
但是程序中寫的域名,不可能寫stub的ip.
如果寫死stub的ip,那么到時候上線時還得改代碼.(只要動代碼,就是有風(fēng)險的)
所以就需要做一個映射.
使用nginx 實現(xiàn)這個功能
配置文件名稱:yunmasoft.com.conf
配置文件內(nèi)容:
server {
listen 80;
server_name yunmasoft.com www.yunmasoft.com;
if ( $uri ~* "^/user/loginInput$" ) {
rewrite ^/(.*)$ http://123.57.250.51/$1 redirect;
}
location / {
proxy_pass http://182.92.97.72:8083;
# proxy_redirect on ;
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
}
效果:
訪問www.yunmasoft.com/user/loginInput 時,就會自動跳轉(zhuǎn)到 http://123.57.250.51/user/loginInput