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 proxy_pass and proxy_redirect

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Proxy_pass: acts as a proxy server and forwards requests

Proxy_redirect: modify the Location in the forwarding process of 301 or 302. The default is proxy_redirect default.

Example:

Location / {

Proxy_pass http://192.168.8.46:8080/; # / ending

# proxy_redirect default # this is the default value, whether it is added or not is the same.

}

In this way, it will be no problem when you proxy to port 8080 of other machines.

Location: http://192.168.8.46/4/, the url address bar of the browser is also http://192.168.8.46/4/

If:

Location / {

Proxy_pass http://192.168.8.46:8080;# removed /

Proxy_redirect off # modify the default value default to off

}

If you remove the last / later, curl-I http://192.168.8.46/4 access

Location: http://192.168.8.46:8080/4/

The address bar displayed for browser access is http://192.168.8.46:8080/4/. (if it is still the previous one, you need to delete the cache first)

As you can see, the real Location address is all exposed. At this time, you need to modify the Location using proxy_redirect.

The configuration is as follows:

Location / {

Proxy_pass http://192.168.8.46:8080;

Proxy_redirect http://192.168.8.46:8080/4/http://192.168.8.46/4/;

}

In this way, you can change the address of Location, Location: http://192.168.8.46/4/, as well as in the browser, so that information such as port number will not be exposed.

Of course, you can also get Location to other websites, such as

Proxy_redirect http://192.168.8.46:8080/4/http://www.douban.com/;

And then the browser skips.

Summary:

The man behind everything is

Proxy_pass http://192.168.8.46:8080; does not add / end, just add /, and proxy_redirect uses the default value to OK.

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