菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
438
0

Nginx 反向代理

原创
05/13 14:22
阅读数 69387
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。 





  

发表评论

0/200
438 点赞
0 评论
收藏
为你推荐 换一批