Difference between last and break in nginxrewrite

Source: Internet
Author: User
In actual configuration, in some cases, using last does not work. You can change it to break. The principle is that you have different understandings of the root directory, which is roughly the same as my test results. # Location {# proxy_passhttp: test; # aliashomehtml; # roothomehtml; # rewrite ^ a (. *) \ .html#1.html last;

In actual configuration, in some cases, using last does not work. You can change it to break. The principle is that you have different understandings of the root directory, which is roughly the same as my test results.

# LoCatIon /{
# Proxy_pass http: // test;
#Alias/Home/html /;
# Root/home/html;
# ReWrite^/A/(. * pai.html $/1.html last;
#}

In the # location/{Configuration:

1. Use root to specify the Source: either last or break can be used.

2. Use proxy_pass to specify the Source: either last or break can be used.

3. Use alias to specify the Source: You must use last

In location/a/or useRegular ExpressionLocation ~ ^/:

1. Use root to specify the Source: either last or break can be used.

2. Use proxy_pass to specify the source: the break and last results are different.

3. Use alias to specify the Source: You must use last

The main difference lies in the proxy_pass label. Let's take a look at several test results:

Location /{
Root/home/html;
}

Location//{
Proxy_pass http: // test;
Rewrite ^/a/(. * pai.html $/1.html last;
}

In this configuration, you can access things using last access. However, the result is:/home/html/1.html; but what I need is http: // test/1.html? Use break.

Location /{
Root/home/html;
}

Location//{
Proxy_pass http: // test;
Rewrite ^/a/(. * pai.html $/a/1.html last;
}

In this configuration section, an error is returned because the last request will re-initiate a request match, resulting in an endless loop. You can use break to access http: // test/a/1.html.

Therefore, using last will re-initiate a request to the server tag, and break will directly use the data source in the current location for access, which should be used as needed. Generally, rewrite is configured in a non-root location, and break is used. It is better to use last for the root location, because if fastcgi or proxy is configured to access the jsp file, using break in the root location cannot be accessed. If there is a problem with rewrite, you may try to replace the two.

When using alias, it is estimated that the last time must be used, which is limited by nginx itself. How to try break cannot be successful.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.