Nginx server reverse proxy proxy_pass configuration method explains
In terms of ordinary reverse proxy, the configuration of Nginx is relatively simple, such as:
location ~ /* {proxy_pass http://127.0.0.1:8008; }
Or can
location / {proxy_pass http://127.0.0.1:8008; }
The configuration of the Apache2 reverse proxy is as follows:
ProxyPass /ysz/ http://localhost:8080/
However, if you want to configure a relatively complex reverse proxy Nginx relative to Apache2 is a little more troublesome, for example, the url starts with /wap/ request forward to the background corresponding to a server can then set a variable in Nginx, to temporarily save the path information after /wap/
location ^~ /wap/ { if ($request_uri ~ /wap/(\d+)/(.+)) { set $bucketid $1; set $params $2; } proxy_pass http://mx$bucketid.test.com:6601/$params; }
Or you can rewrite first, and then delegate:
location ^~ /wap/{ rewrite /wap/(\d+)/(.+) /$2? $args break; proxy_pass http://mx$1.test.com:6601; }
perhaps
location ~* /wap/(\d+)/(.+) { proxy_pass http://mx$1.test.com:6601/$2?$args; }
Notice the last one at the top? If you use a variable in proxy_pass (either the hostname variable $1 or the $2 variable after it), you must add this code, but if pass_proxy doesn't use any variables, you don't need to add this code. By default, it will give all urls to the proxy in the background, such as:
location ~* /wap/(\d+)/(.+) { proxy_pass http://mx.test.com:6601; }
Apache2 is much simpler:
ProxyPassMatch ^ / wap/(. *) $http://192.168.132.147/$1 if ($host WWW. ~ * (. *)) {set $host_without_www $1; rewrite (.*)$ http://$host_without_www/www$1; }
When proxy_pass is configured in nginx, when/is added to the following url, which is equivalent to the absolute root path, nginx will not proxy the matched path in location; If there is no /, the matching part of the path is also given to the agent. The following four cases with http://192.168.1.4/proxy/test.html for a visit. The first:
location /proxy/ {proxy_pass http://127.0.0.1:81/; }
Is the agent to the url http://127.0.0.1:81/test.html second za (relative to the first one, last one less /)
location /proxy/ {proxy_pass http://127.0.0.1:81; }
Third: is the agent to the url http://127.0.0.1:81/proxy/test.html
The location/proxy / {proxy_pass http://127.0.0.1:81/ftlynx/; }
Is the agent to the url http://127.0.0.1:81/ftlynx/test.html. Fourth case (last one less/than third) :
The location/proxy / {proxy_pass http://127.0.0.1:81/ftlynx; }
Is the agent to the url http://127.0.0.1:81/ftlynxtest.html the results above are my combining with log files have been tested. As can be seen from the results, it is correct to say that there are two cases. The http://127.0.0.1:81 (the second) the and http://127.0.0.1:81/... (1,3,4 above) This.
- How to set Nginx as a reverse proxy to pass client IP addresses
- An example of load balancing implemented by nginx as a reverse proxy
- The Nginx server serves as the reverse proxy to implement the url forwarding configuration on the Intranet
- Nginx reverse proxy websocket configuration instance
- Nginx implements reverse proxy instances of static resources
- Nginx real combat reverse proxy WebSocket configuration example
- nginx https reverse proxy Two ways to implement tomcat
- Discard Nginx and use nodejs as the reverse proxy server
- Method steps for deploying Nginx for reverse proxy in Linux
Related article
-
How does Nginx proxy UDP connections
This article mainly introduces how to implement Nginx proxy UDP connection in detail, friends in need can use for reference, I hope to be helpful, I wish you a lot of progress, early promotion and pay rise2023-06-06 -
nginx reverse proxy file download failure and solution
This article mainly introduces the nginx reverse proxy file download failure problem and solution, has a good reference value, I hope to help you, if there are mistakes or not considered completely, please feel free to advise2023-12-12 -
Code example of nginx forwarding Intranet pictures
This article mainly introduces nginx forwarding Intranet pictures to you. The article is introduced in great detail through code examples, which will be helpful to your study or work. Interested partners can try it for themselves2023-10-10 -
Nginx+Tomcat high-performance load balancing cluster setup tutorial
This article mainly introduces Nginx+Tomcat high-performance load balancing cluster construction tutorial in detail, has a certain reference value, interested partners can refer to it2018-04-04 -
The entire process of the nginx reverse proxy
This article mainly introduces the whole process of nginx reverse proxy, has a good reference value, I hope to help you, if there are mistakes or not considered completely, please feel free to advise2023-12-12 -
502 Causes of Bad Gateway and summary of 8 detailed solutions
Nginx 502 Bad Gateway error has been encountered several times, here to make a record, memo, the following article mainly introduces the causes of 502 Bad Gateway and 8 detailed solutions, the introduction is very detailed, the need of friends can refer to2023-05-05 -
Nginx configures the location module to implement the routing (reverse proxy, redirection) function
This article mainly introduces the Nginx configuration location module to achieve routing (reverse proxy, redirection) function, the article through the example code introduction is very detailed, for everyone's study or work has a certain reference learning value, the need of friends below with the small series to learn together2022-04-04 -
How does Nginx configure the inheritance model
This article mainly introduces a detailed explanation of how to configure the inheritance model of Nginx, Xiaobian feel very good, now share with you, but also give you a reference. Let's take a look2018-07-07 -
Nginx method for hiding various types of information on the server
This article mainly introduces the method of Nginx hiding all kinds of information on the server side, including hiding HTTP header information and PHP version number, etc., need friends can refer to the next2015-07-07 -
This section describes how to configure nginx reverse proxy webSocket
This article mainly introduces the nginx reverse proxy webSocket configuration detailed, Xiaobian feel very good, now share with you, also give you a reference. Let's take a look2018-10-10
Latest comments