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

Nginx forwarding configuration

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Nginx configures proxy_pass forwarding / path issues

When configuring proxy_pass in nginx, if you match the path according to ^ ~, you should pay attention to the last / of the url after proxy_pass. When / is added, which is equivalent to the absolute root path, nginx will not take part of the matching path in location as an agent; if there is no /, it will also give the matching part of the path to the agent.

Location ^ ~ / static_js/

{

Proxy_cache js_cache

Proxy_set_header Host js.test.com

Proxy_pass http://js.test.com/;

}

As configured above, if the requested url is http://servername/static_js/test.html

Will be represented as http://js.test.com/test.html.

And if configured in this way,

Location ^ ~ / static_js/

{

Proxy_cache js_cache

Proxy_set_header Host js.test.com

Proxy_pass http://js.test.com;

}

Will be represented to http://js.test.com/static_js/test.htm

Of course, we can use the following rewrite to achieve /

Location ^ ~ / static_js/

{

Proxy_cache js_cache

Proxy_set_header Host js.test.com

Rewrite / static_js/ (. +) $/ $1 break

Proxy_pass http://js.test.com;

}

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

Servers

Wechat

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

12
Report