In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use nginx to implement a request forwarding function. Here, it is introduced in great detail through the example code, which has a certain reference value for your study or work. Friends who need it can refer to it:
Reverse proxy is suitable for many situations, and load balancing is the most common use.
As one of the most popular web servers at present, nginx can easily implement reverse proxy.
Nginx reverse proxy official document: NGINX REVERSE PROXY
When multiple different web servers are deployed on a single host and you need to be able to access these web servers on port 80 at the same time, you can use the reverse proxy feature of nginx: use nginx to listen for all requests on port 80 and forward them to the corresponding web server according to the forwarding rules (it is more common to forward them as URI).
For example, there are webmail, webcom and webdefault servers running on portmail, portcom and portdefault ports respectively. To access these three web servers simultaneously from port 80, you can run nginx on port 80, then forward the requests under / mail to the webmail server, forward the requests under / com to the webcom server, and forward all other requests to the webdefault server.
Assuming that the server domain name is example.com, the corresponding nginx http configuration is as follows:
Http {server {server_name example.com; location / mail/ {proxy_pass http://example.com:protmail/;} location / com/ {proxy_pass http://example.com:portcom/main/;} location / {proxy_pass http://example.com:portdefault;}
The above configuration forwards requests according to the following rules (both GET and POST requests are forwarded):
Forward the request under http://example.com/mail/ to http://example.com:portmail/
Forward the request under http://example.com/com/ to http://example.com:portcom/main/
Forward all other requests to http://example.com:portdefault/
It should be noted that in the above configuration, the proxy server settings for webdefault do not specify URI, while the proxy server settings for webmail and webcom specify URI (/ and / main/, respectively).
If there is a URI in the proxy server address, this URI replaces the URI part that the location matches.
If there is no URI in the proxy server address, the full request URL is forwarded to the proxy server.
Official document description:
If the URI is specified along with the address, it replaces the part of the request URI that matches the location parameter.
If the address is specified without a URI, or it is not possible to determine the part of URI to be replaced, the full request URI is passed (possibly, modified).
Example of forwarding in the above configuration:
Http://example.com/mail/index.html-> http://example.com:portmail/index.htmlhttp://example.com/com/index.html-> http://example.com:portcom/main/index.htmlhttp://example.com/mail/static/a.jpg-> http://example.com:portmail/static/a.jpghttp://example.com/com/static/b.css-> http://example.com:portcom/main/static/b. Css http://example.com/other/index.htm-> http://example.com:portdefault/other/index.htm, so much for this article on how to implement a request forwarding function using nginx. For more information about how to use nginx to achieve a request forwarding function, please search for previous articles or continue to browse the relevant articles below. I hope you will support it in the future!
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.