Home >Backend Development >PHP Tutorial >nginx rewite command module

nginx rewite command module

WBOY
WBOYOriginal
2016-07-29 09:12:521325browse

Introduction: nginx, as a reverse proxy server, sometimes needs to modify the uri in the http request;

nginx rewrite module contains instructions

  • break
  • if
  • return
  • rewrite
  • rewrite_log

nginx rewrite Module Introduction

The ngx_http_rewrite_module module is used to change request URI using regular expressions, return redirects, and conditionally select configurations.

mainly includes three methods,regular expressionschange uri, directly return jump 301, 302, return 404, 501 errors; modify uri according to conditions;

nginx rewrite module instructions execution sequence

The instructions of this module can appear under server/location, and of course in the if block;

  • the directives of this module specified on the server level are executed sequentially;
  • repeatedly:
    • a location is searched based on a request URI;
    • the directives of this module specified inside the found location are executed sequentially;
    • the loop is repeated if a request URI was rewritten, but not more than 10 times.

tag of rewrite directive

<code><span>Syntax</span>: <span>rewrite regex replacement [flag];</span><span>Default</span>: <span>   —</span><span>Context</span>: <span>   server, location, if</span></code>
  • last ; stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI;
  • break ; stops processing the current set of ngx_http_rewrite_module directives as with the break directive;
  • redirect; returns a temporary redirect with the 302 code; used if a replacement string does not start with “http://” or “https://”;
  • permanent ; returns a permanent redirect with the 301 code.

These four flags are not necessary. If [flag] is missing, the order will be executed downwards;

Flowchart

nginx rewite指令模块

').addClass ('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

The above introduces the nginx rewite command module, including regular expressions. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn