Nginx: proxy_pass

  

proxy_pass 分两种情况:

location 非正则:  query string无需手动传递, nginx会自动附加

  proxy_pass 后可为upstream server或直接写后端某个主机地址

 

  1. proxy_pass 后无URI时, location 匹配的全部URI 都附加到proxy_pass的主机后
  2. proxy_pass 后有URI时, location 匹配的全部URI, 但要去除写在location后的匹配条件的路径, 都附加到proxy_pass的主机后

 

location 为正则:  ~ ~*  query string必须手动传递给后端, 否则丢失

  proxy_pass 后必须为upstream server, 直接写某个主机地址(直接写主机地址不跟URI时, nginx -t通过)时, 会报502, 很坑 **************  

  1. 后跟URI, 则必须写正则匹配的 $1 或 $name, 否则query string都会丢失  
  2. 后不跟URI时, Nginx会自动附加匹配URI & query string

 

 

 

 

 

 

 

 

 

ram1 nginx 配置

  

ram2 tomcat 配置

 

 

  

 

重定向发生在tomcat 

 

 

  

 

 

404原因:

proxy_pass 使用变量的话, nginx不会自动添加path到host后, 转发地址即为 http://ram2.concerto.com:8080/vv, 即有变量的转发地址, 只是proxy_pass的内容, 需手动添加其他信息

  

 

 Ameliorate:

  

 

 

 

  

 

 

不丢失参数

 

 

 

 

 

 

 

如何解决 nginx proxy_pass 使用变量 $arg 404 ? - SegmentFault 思否

posted @ 2021-10-06 15:56  ascertain  阅读(2515)  评论(0)    收藏  举报