In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to set up proxy_pass in Nginx? for this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Nginx is suitable for reverse proxy [Reverse-Proxy] for the following reasons.
The high performance feature of Nginx allows Hold to live more connections.
A more mature Internet-oriented design can enhance the security of back-end servers.
It is convenient to scale out the performance and enhance the data processing ability.
Based on the above advantages, how to configure the Nginx reverse proxy correctly?
There are two situations.
The first case: the designation after proxy_pass with URI
The URI matched by the location will be replaced by the URI after the proxy_pass. Examples are as follows
Location / requested-uri/ {
Proxy_pass http://example.com/backend/;
}
At this point, if the requested connection is http://proxy-ip/requested-uri/a.html, the path transferred to the backend will become http://example.com/backend/a.html.
Verify as follows:
Scenario: two links are created on tomcat, http://10.2.0.51:8000/zzp/app1 and http://10.2.0.51:8000/zzp/app2
The two links display different content, app1 and app2
Then we configure it in nginx as follows:
Location / zzy/ {
Proxy_pass http://10.2.0.51:8000/zzp/;
}
At this point, when we visit http://10.2.0.51/zzy/app1, we will find that we will get app1, indicating that the URI of zzy has been replaced by zzp.
The second case: when there is no URI after the proxy_pass, the URI is transferred directly to the back-end server. Examples are as follows
Location / requested-uri/ {
Proxy_pass http://example.com;
}
At this point, if the requested connection is http://proxy-ip/requested-uri/a.html, then the path transferred to the backend will become http://example.com/requested-uri/a.html.
Verify as follows:
In the previous example, we do not have uri in proxy_pass. When we visit the uri of zzy, we will find that there is a 404 error.
Location / zzy/ {
Proxy_pass http://10.2.0.51:8000;
}
Modify the configuration as follows
Location / zzp/ {
Proxy_pass http://10.2.0.51:8000;
}
When you visit http://10.2.0.51/zzp/app1, it is adjusted.
Exceptions:
There are always exceptions, and so is Nginx.
Special case: in versions prior to 1.1.12, in some cases, proxy_pass instructions without URI were replaced by instructions.
General exception:
When location is followed by a regular expression, proxy_pass is not followed by URI.
Because, if location has a regular expression, nginx cannot determine which part of the URI matches the expression.
When the URI is modified with the rewrite instruction, and the same configuration will be used to process a request. For example, this one is easy to twist. Boring
Location / name/ {
Rewrite / name/ ([^ /] +) / users?name=$1 break
Proxy_pass http://127.0.0.1;
}
When a variable is used in prox_pass, it will be replaced by the following.
Location / name/ {
Proxy_pass http://127.0.0.1$request_uri;
}
All in all, as long as we do not touch the conditions under which exceptions occurs, we can achieve our goal. If exceptions appears accidentally, then come here to study it.
Basic is import, and should be studied in details.
This is the answer to the question about how to set up proxy_pass in Nginx. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.