欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nginx rewrite nginx rewrite 

程序员文章站 2022-06-17 13:26:39
...

rewrite

 

server {
#需要转发的监听端口,
listen 80;
server_name localhost;

#access_log logs/host.access.log main;
#Used & Product Api
#所以的path(/)都可以进这个location进行匹配
location / {
root html;
index index.html index.htm;

proxy_pass http://0.0.0.0:30008/;
#加break表示本条规则匹配完成后,终止匹配,不再匹配后面的规则。
rewrite ^/provider/rmsj/rps_search_2.7/product.json /Product break;
}


#Category Apis
#path符合这个规则(^~/provider/rmsj/category/)的才可以进这个location进行匹配
location ^~/provider/rmsj/category/ {
root html;
index index.html index.htm;

#转发到其他host或者port
proxy_pass http://0.0.0.0:30003/;
rewrite ^/provider/rmsj/category/category_set/all/get /CategorySetsGet break;
rewrite ^/provider/rmsj/category/category/all/get /CategorysGet break;
rewrite ^/provider/rmsj/category/category/get /CategoryGet break;
rewrite ^/provider/rmsj/category/category/post /CategoryInsert break;
rewrite ^/provider/rmsj/category/category/put /CategoryUpdate break;
rewrite ^/provider/rmsj/category/category/delete /CategoryDelete break;
rewrite ^/provider/rmsj/category/category/move /CategoryMove break;
}

#Navigation Api
location ^~/provider/rmsj/navigation/ {
root html;
index index.html index.htm;

proxy_pass http://0.0.0.0:30005/;
if ($arg_operation = 'GenreSearch') {
rewrite ^/provider/rmsj/navigation/search /GenreGet break;
}
if ($arg_operation = 'GenreAndTagSearch') {
rewrite ^/provider/rmsj/navigation/search /GenreTagGet break;
}
if ($arg_operation = 'Header') {
rewrite ^/provider/rmsj/navigation/search /GenreHeaderGet break;
}
}
}

rewrite参考正则表达式规则

"$arg_"作为前缀加在parameter名之前,可以获得该parameter的值,如operation=GenreSearch,那么$arg_operation就可以获取值GenreSearch。

 

本文只介绍了我用到的内容,其他可以参考http://www.linuxidc.com/Linux/2014-01/95493.htm

 

相关标签: nginx rewrite