Let's talk about the difference first
Nginx configuration file server { listen 88; server_name _; location /break { # location 1 rewrite ^/break/(.*)$ /bak/$1 break; } location /last { # location 2 rewrite ^/last/(.*)$ /bak/$1 last; } location /bak { # location 3 default_type text/html; return 200 $uri; } } Visit http://rumenz.com:88/break/one When location1 is hit, the browser address bar does not change. It goes directly to find the /nginx/html/bak/one file. Since there is no such file, 404 is returned. Browser Nginx error (error.log) log /nginx/html/bak/one failed (2: No such file or directory) break means stop after rewriting and no longer match the location block. Visit http://rumenz.com:88/last/one Hit location2, the browser address bar does not change, re-match to location3 last means to jump to the location block after rewriting and match it with the rewritten address again Use cases for break and last break File download, hide and protect the real file server. location /down { rewrite ^/down/(.*)$ https://rumenz.com/file/$1 break; } last Rewrite the interface address, rewrite https://rumenz.com/api/list to https://rumenz.com/newapi/list location /api { rewrite ^/api/(.*)$ /newapi/$1 last; } location /newapi { default_type Application/json; return 200 '{"code":200,"msg":"ok","data":["JSON.IM","json format"]}'; } Summarize This is the end of this article about the difference between break and last in Nginx. For more information about the difference between break and last in Nginx, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Vue's detailed code for implementing the shuttle box function
>>: How to distinguish MySQL's innodb_flush_log_at_trx_commit and sync_binlog
1. Question: I have been doing insert operations ...
Preface MySQL is the most popular relational data...
In Nginx, there are some advanced scenarios where...
The following are all performed on my virtual mac...
How to convert a JSON string into a JSON object? ...
Table of contents Overview 1. Path module 2. Unti...
Overview Databases generally execute multiple tra...
In the WeChat applet project, the development mod...
Table of contents 1. Requirements description 2. ...
Table of contents Download the compressed file Ad...
For example: Copy code The code is as follows: <...
Table of contents Methods that do not change the ...
This article shares the specific code of jQuery t...
This article shares the specific code of JavaScri...
Nginx hides version number In a production enviro...