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

How to implement Nginx routing forwarding and reverse proxy location configuration

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to achieve Nginx routing forwarding and reverse proxy location configuration", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to achieve Nginx routing forwarding and reverse proxy location configuration"!

Three ways to configure Nginx

The first method directly replaces the matching part of location

The destination address of the second kind of proxy_pass, which does not take / by default, means that only the proxy domain name will be represented, and the url and parameter parts will not be changed (the URL used as the proxy after the requested path is spliced into the proxy_pass target domain name)

If the destination address of the third type of proxy_pass is added with /, it means that the successful part of the location match in the path is cut off and then added to the proxy_pass destination address.

Location configuration

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

The contents in square brackets before the uri are optional and are explained as follows:

"=": before using standard uri, the request string is required to match the uri strictly. Once the match is successful, it will be stopped.

"~": used in front of regular uri and case sensitive

"~ *": used before regular uri, but not case-sensitive

"^ ~": before using standard uri, Nginx is required to find the location that identifies the uri and the request string with the highest matching degree, and immediately uses this location to process the request instead of matching the regular uri and the request string in the location block

Symbolic meaning = exact matching ^ ~ irregular matching ~ regular matching (case-sensitive) ~ * regular matching (case-insensitive)! ~ regular mismatch (case-sensitive)! ~ * regular mismatch (case-insensitive) normal match (when there is no symbol here)

Examples

For example, the following configuration demonstrates the third configuration scenario, when we access http://44.179.118.54:80/shop/xxx

During the visit, Nginx will intercept / shop/ and then attach the following path to proxy_pass.

So what we actually visit is the http://44.179.118.54:8007/xxx service.

# shop-service # reverse proxy shop-service Service location ^ ~ / shop/ {# proxy_redirect off; # proxy_connect_timeout 60; # proxy_read_timeout 60; # proxy_send_timeout 60; # proxy_buffer_size 4k; # proxy_buffers 4 32k; # proxy_busy_buffers_size 64k; # proxy_temp_file_write_size 64k; # proxy_max_temp_file_size 128m Proxy_pass http://44.179.118.54:8007/; # proxy_set_header X-Real-IP $remote_addr; # root / var/www/test/user/ # index index.html # proxy_pass https://www.baidu.com; } Thank you for your reading. The above is the content of "how to implement Nginx routing forwarding and reverse proxy location configuration". After the study of this article, I believe you have a deeper understanding of how to achieve Nginx routing forwarding and reverse proxy location configuration, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Development

Wechat

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

12
Report