Nginx: rewrite Rewrite Module

A configuration

  1. rewrite the purpose of "http: //" or "https: //": direct return after the end of the 302 temporary redirect rewrite the handler.
  2. last: After the last line command has resolved the end, will fill the final NULL in an array of codes, so the same area behind a rewrite related instructions are no longer effective.
  3. break: r-> uri_changed will be assigned to 0, in POST_REWRITE stage, perform r-> phase_handler ++, so go directly to the next stage. break also the end of the last of the property.
  4. redirect: 302 temporary redirect returned directly after the end of the handler.
  5. permanent: 303 permanent direct return after the heavy qualitative handler.

Second, the process

  1. server_rewrite and the difference location_rewrite
    for server_rewrite and rewrite two stages, the processing flow is almost no difference. Just a different code of objects, server and location of ngx_http_rewrite_loc_conf_t are two different spaces.

    1) In the previous stage 11, when the parsed host, calls ngx_http_set_virtual_server block query server, and the following assignment:

    r->srv_conf = cscf->ctx->srv_conf;
    r->loc_conf = cscf->ctx->loc_conf;

    Therefore, server_rewrite phase obtained ngx_http_rewrite_loc_conf_t server block belongs.

    2) In NGX_HTTP_FIND_CONFIG_PHASE stage before location_rewrite, will be location a block search, and r-> loc_conf reassigned, so at this time acquired ngx_http_rewrite_loc_conf_t belongs location of the block.

  2. rewrite jump
    Here Insert Picture Description
    after 1) for the rewrite ordinary non-break, redirect, permanent, and if a hit NGX_HTTP_REWRITE_PHASE redirection, then after NGX_HTTP_POST_REWRITE_PHASE (the phase ph-> next = find_config_index) execution jumps to NGX_HTTP_FIND_CONFIG_PHASE, redirect Find the location.
    2) For the rewrite break after hitting the redirect will not return FIND_CONFIG stage.
    3) internal redirect Stage Jump:

    . a server_rewrite_index:
    For r-> internal 1 and calls upon ngx_http_handler re-take the stage, will be assigned "R-> phase_handler =
    cmcf-> phase_engine.server_rewrite_index", the process after skipping POST_READ, direct access to SERVER_REWRITE stage. Two current condition is satisfied:
    1) all the sub-requests;
    2) internal redirect function call ngx_http_internal_redirect.
    For example, post_action field, a request URI is defined as the completion of the current request child.

    location /protected_files { 
      	internal;
    	proxy_pass http://127.0.0.2;
    	post_action /protected_done;
    }
    

    For example, index module, for the first character of "/" index, perform an internal redirect. For example, try_files $ uri /index.php.

    b location_rewrite_index:.
    For the configuration using the "!" redirection is typically called ngx_http_named_location request redirection URI, find locaiton blocks, and assign "R-> phase_handler
    = cmcf-> phase_engine.location_rewrite_index", a subsequent process Jump to NGX_HTTP_REWRITE_PHASE stage. (Referred to as its rewrite, is better known as foward, the request does not modify uri) satisfies the above conditions are present:
    . 1) try_files $ uri @abc;
    2) error_page 403 @abc;
    x_accel_redirect. 3) @ beginning.

Guess you like

Origin blog.csdn.net/u013032097/article/details/91388081