码迷,mamicode.com
首页 > 其他好文 > 详细

nginx proxy

时间:2021-01-21 10:52:23      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:$1   set   serve   name   server   请求   ati   pat   list   

listen 80;
server_name localhost;

# 访问"localhost"的全部请求会被转发到"localhost:81"
# localhost => localhost:81
# localhost/a/ => localhost:81/a/
# localhost/b/ => localhost:81/b/
location / {
 proxy_pass http://localhost:81;
}

# 访问"localhost"的全部请求会被转发到"localhost:81/a/"
# localhost => localhost:81/a/
# localhost/a/ => localhost:81/a/a/
# localhost/b/ => localhost:81/a/b/
location / {
 proxy_pass http://localhost:81/a/;
}


# 访问"localhost/c/"的全部请求会被转发到"localhost:81/a/"
# localhost => 不会转发
# localhost/c/ => localhost:81/a/
# localhost/c/aa/ => localhost:81/a/aa/
location /c/ {
 proxy_pass http://localhost:81/a/;
}

# 访问"localhost/api/"的全部请求会被转发到"localhost:81"
# localhost => 不会转发
# localhost/api/ => localhost:81
# localhost/api/a/ => localhost:81/a/
# localhost/api/b/ => localhost:81/b/
location /api/ {
  # rewrite 的作用是修改URI
  rewrite ^/api(/.*)$ $1 break;
  proxy_pass http://localhost:81;
}

# http://localhost/api/ => http://127.0.0.1:81/
# http://localhost/api/a/ => http://127.0.0.1:81/a/
# http://localhost/api/b/ => http://127.0.0.1:81/b/
# http://localhost/api/?path=/a => http://127.0.0.1:81/a
# http://localhost/api/?path=/b => http://127.0.0.1:81/b
location /api/ {
  if ($arg_path = ‘‘) {
    rewrite ^/api(/.*) $1 break;
    set $arg_path $1;
  }
  proxy_pass http://127.0.0.1:81$arg_path;
}

nginx proxy

标签:$1   set   serve   name   server   请求   ati   pat   list   

原文地址:https://www.cnblogs.com/ajanuw/p/14305212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!