Nginx 反向代理

upstream test {
server  127.0.0.1:8080;
}


upstream v2.c.y.com {
server  1.159.227.3;
}

upstream auth.y.com {
server  1.159.227.3;
}

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;



        location /api/userCredit/calculateLocalPayment {
            proxy_pass http://test;

            root   html;
            index  index.html index.htm;
        }
        location /api/userCredit/getBalance {
            proxy_pass http://test;

            root   html;
            index  index.html index.htm;
        }
        
        location /api/userCredit/pay {
            proxy_pass http://test;

            root   html;
            index  index.html index.htm;
        }
        location / {
            proxy_pass http://v2.clientapi.y.com;

            root   html;
            index  index.html index.htm;
        }

location /token {
            proxy_pass http://auth.y.com;

            root   html;
            index  index.html index.htm;
        }

返回json
location ~ ^/get_json {
    default_type application/json;
    return 200 '{"status":"success","result":"nginx json"}';
}

匹配模式及顺序

  location = /uri    =开头表示精确匹配,只有完全匹配上才能生效。

  location ^~ /uri   ^~ 开头对URL路径进行前缀匹配,并且在正则之前。

  location ~ pattern  ~开头表示区分大小写的正则匹配。

  location ~* pattern  ~*开头表示不区分大小写的正则匹配。

  location /uri     不带任何修饰符,也表示前缀匹配,但是在正则匹配之后。

  location /      通用匹配,任何未匹配到其它location的请求都会匹配到,相当于switch中的default。 





  

posted @ 2018-08-22 12:28  ahuo  阅读(343)  评论(1编辑  收藏  举报