Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The method of configuring Location from scratch in Nginx

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the Nginx Location from scratch configuration method related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that after reading this Nginx Location from scratch configuration method article will have a harvest, let's take a look.

Basic knowledge

The matching order of location is "match regular first, match normal".

The matching order of location is actually "matching normal first, then matching regular". The reason for the misunderstanding is that regular matching will override ordinary matching.

Nginx location configuration syntax

1. Location [= | ~ | ~ * | ^ ~] uri {.}

2. Location @ name {...}

Location configuration can be configured in two ways

1. Prefix + uri (string / regular expression)

2. @ + name

Prefix meaning

=: exact match (must be all equal)

~: case sensitive

~ *: ignore case

^ ~: only need to match the uri part

@: internal service redirection

Basic knowledge of location

1.location is configured in the server block.

two。 You can use different configurations (configured in location) according to different uri to handle different requests.

The 3.location is sequential and will be processed by the first matching location.

Location configuration demo

1. Exact match

Location = / {# Rule} # matches the request of `http://www.example.com/`.

2. Case-sensitive

Location ~ / example/ {# Rule} # request example # http://www.example.com/example/ [successful] # http://www.example.com/example/ [failed]

3.ignore upper and lower case

Location ~ * / example/ {# Rule} # ignores the case of the uri section # http://www.example.com/example/ [success] # http://www.example.com/example/ [success]

4.^ ~, matches only start with uri

Location ^ ~ / img/ {# Rule} # all requests starting with / img/ will match with # http://www.example.com/img/a.jpg [success] # http://www.example.com/img/b.mp4 [success]

5. Internal jump of fugitive _ nginx

Location / img/ {error_page 404 @ img_err;} location @ img_err {# Rule} # A request that starts with / img/ if the status of the link is 404. Will match to the @ img_err rule. This is the end of the article on "how to configure Location from scratch in Nginx". Thank you for reading! I believe you all have a certain understanding of "the method of configuring Location from scratch in Nginx". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report