Nginx 反向代理
  7gZJoSEULaLm 2023年11月02日 59 0
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。 





【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

7gZJoSEULaLm