asdrtu 发表于 2018-11-14 06:22:33

nginx proxy_pass转发路径

  当proxy_pass url最后加上了/ 相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走; 如果没有/,则会把匹配的路径部分也给代理走.举例如下:
  假设请求url: http://www.test.com/static/js/us.js
  location ^~ /static/
  {
  proxy_pass http://192.168.1.11:8081/;
  }
  不带location中的东西,代理实际URL为 http://192.168.1.11:8081/js/us.js
  location ^~ /static/
  {
  proxy_pass http://192.168.1.11:8081;
  }
  带location中的东西,代理实际URL为 http://192.168.1.11:8081/static/js/us.js
  #############################################################################################
  proxy_pass到域名注意事项
  #############################################################################################
  如果proxy_pass是直接指向的域名,nginx在启动的时候会缓存域名解析的IP。此时修改域名解析的IP,那么nginx默认将不会解析到新IP上除非reload才会生效。改换成如下配置则更换IP解析后nginx会自动重新查询域名解析。
  resolver 8.8.8.8 8.8.4.4 valid=60s;
  set $url "http://abc.test.com";
  proxy_pass $url;
  参考:http://www.cnblogs.com/kevingrace/p/6566119.html

页: [1]
查看完整版本: nginx proxy_pass转发路径