nginx的rewrite

设置nginx的rewrite如果替换项是以http://开头,则起的是redirect的作用,即使最后的参数是last不是redirect,例如:

rewrite ^(.*)$ http://aaa.bbb.com/ccc$1 last;

浏览器端会得到302。

nginx的文档里提到:

redirect – returns temporary redirect with code 302; it is used if the substituting line begins with http://

另外,rewrite后的host的使用顺序如下:

  1. 当请求的http头里的host匹配sever_name里的任一host时,使用此host
  2. 若不匹配,或者为空,使用server_name的第一个host
  3. 若没有设置server_name,则使用本机的hostname
  4. 若要一直使用http头里的host,则将server_name设置为:servername _ *;(下划线不能少,因为 * 不能做为sever_name第一项的开头)
This entry was posted in nginx, 运维 and tagged , . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

Note: If you are replying to another commenter, click the "Reply to {NAME} ↵" button under their comment!