Get the App
SLTechnology News&Howtos  ›  Servers  › 

Difference and principle Analysis of forward reverse Agent in Nginx

Shulou Source: shulou.com Published: 2022-06-02 01:58:32 09月25日 Update

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.

Tags: Agent server service client client path configuration destination address actual that is data browser browse original port end package monitor above Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Apple MySQL Huawei Redmi