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 influence of proxy_pass on back-end request in nginx virtual path

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

Share

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

Suppose the configuration in nginx looks like this:

Server {

Listen 80

Server_name x.x.x.x

. . . . . .

Location / subdir

{

Proxy_pass http://y.y.y.y;

}

}

Then, when the user requests http://x.x.x.x/subdir/other, matching to that block, nginx reverse proxies to the backend will retain the virtual path. The request URL that nginx actually initiates to the backend is http://y.y.y.y/subdir/other.

Suppose the configuration in nginx looks like this:

Server {

Listen 80

Server_name x.x.x.x

. . . . . .

Location / subdir

{

Proxy_pass http://y.y.y.y/;

}

}

Then, when the user requests http://x.x.x.x/subdir/other, the block is matched, and because the backend URI path is specified in the proxy_pass, the nginx agent will not retain the virtual path when it requests to the backend. The request URL that nginx actually initiates to the backend is http://y.y.y.y//other.

Suppose the configuration in nginx looks like this:

Server {

Listen 80

Server_name x.x.x.x

. . . . . .

Location / subdir

{

Proxy_pass http://y.y.y.y/upstream_subdir;

}

}

Then, when the user requests http://x.x.x.x/subdir/other, the block is matched, and because the backend URI path is specified in the proxy_pass, the nginx agent will not retain the virtual path when it requests to the backend. The request URL that nginx actually initiates to the backend is http://y.y.y.y/upstream_subdir/other.

Summing up the above three examples, we can find that the crux of the problem is whether the URI of the specified backend server is specified in the proxy_pass instruction, which determines whether the virtual path in the location will be retained when the nginx proxy requests to the backend.

When the back-end server is written in upstream mode, the effect is the same. For example:

Upstream backend {

Server y.y.y.y:80

}

Server {

Listen 80

Server_name x.x.x.x

. . . . . .

Location / subdir

{

Proxy_pass http://backend/upstream_subdir;

}

}

When a user requests a http://x.x.x.x/subdir/other, the actual request URL that the nginx initiates to the backend is still http://y.y.y.y/upstream_subdir/other.

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