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

Difference and principle Analysis of forward reverse Agent in Nginx

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

Share

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

I. the difference between forward proxy and reverse proxy

Forward proxy client, reverse proxy server.

1.1 forward Agent

The forward proxy server lies between the client and the server. in order to obtain data from the server, the client sends a request to the proxy server and specifies the target server, and the proxy server transfers the data returned by the target server to the client. Here the client needs to make some forward proxy settings.

For example: climbing over the wall

What is being proxied in the forward agent is the request of the client.

1.2 reverse proxy

Reverse proxy, the client is not aware of the proxy, and the client can access it without any configuration. The client sends the request to the reverse proxy server, and the reverse proxy server selects the target server to obtain data, and then returns it to the client. At this time, the reverse proxy server and the target server are external servers, exposing the proxy server address and hiding the real server IP address.

Second, the use of nginx reverse proxy

Create a new virtual host configuration in the nginx configuration file nginx.conf

Server {listen 8080; server_name localhost; location / category/ {proxy_pass http://localhost;}}

In the above configuration

Listen indicates the port on which nginx listens

Server_name is the domain name entered in the browser when accessing nginx. You can enter the ip address directly. If you want to bind multiple domains, you can separate them with spaces.

Location indicates the url to match when the nginx listens on the port. If the url that accesses the nginx contains / category/, execute the proxy.

Proxy_pass represents the target to which nginx proxies the client's request.

Note that the path of proxy_pass is written here. If, as above, the path ends without /, which means a relative path, then nginx will not truncate the / category/ in the original url when forwarding the request. For example, if the browser accesses http://localhost:8080/category/findAll, the actual request address sent by nginx is http://localhost/category/findAll.

If the destination path of the proxy_pass is configured with / at the end, which indicates the absolute path, the nginx will intercept the / category/ in the original url when forwarding the request. For example, if the browser accesses the http://localhost:8080/category/findAll, the actual request address sent by the nginx is http://localhost/findAll.

In the configuration, you should decide whether you need to take / according to your own needs, otherwise nginx will always report 404 errors in actual use.

My configuration here is because / category is included in my back-end interface path, so I use the relative path and keep this.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support 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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report