Loading

nginx 转发配置

proxy_pass

假设下面四种情况分别用 http://192.168.1.1/proxy/test.html 进行访问。

  • 第一种:
server {
  listen 80;
  server_name example.com; // 接口的域名
  // ... 
  location /proxy/ {
    proxy_pass http://127.0.0.1/;
  }
}

代理到URL:http://127.0.0.1/test.html

  • 第二种(相对于第一种,最后少一个 / )
server {
  listen 80;
  server_name example.com; // 接口的域名
  // ... 
  location /proxy/ {
    proxy_pass http://127.0.0.1;
  }
}

代理到URL:http://127.0.0.1/proxy/test.html

  • 第三种:
server {
  listen 80;
  server_name example.com; // 接口的域名
  // ... 
  location /proxy/ {
    proxy_pass http://127.0.0.1/aaa/;
  }
}

代理到URL:http://127.0.0.1/aaa/test.html

  • 第四种(相对于第三种,最后少一个 / )
server {
  listen 80;
  server_name example.com; // 接口的域名
  // ... 
  location /proxy/ {
    proxy_pass http://127.0.0.1/aaa;
  }
}

代理到URL:http://127.0.0.1/aaatest.html

参考:https://www.jianshu.com/p/b010c9302cd0

posted @ 2022-06-29 15:54  ZJH_BLOGS  阅读(7366)  评论(0编辑  收藏  举报