Difference and principle analysis of Nginx forward and reverse proxy

Difference and principle analysis of Nginx forward and reverse proxy

1. The difference between forward proxy and reverse proxy

A forward proxy acts as a proxy for the client, and a reverse proxy acts as a proxy for the server.

1.1 Forward Proxy

A forward proxy server is located 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. The proxy server then forwards the data returned by the target server to the client. Here the client needs to make some forward proxy settings.

Example: Climbing the Wall

In a forward proxy, the client's request is proxied

1.2 Reverse Proxy

In the reverse proxy, the client is unaware of the proxy and can access it without any configuration. The client sends the request to the reverse proxy server, which selects the target server to obtain the data and then returns it to the client. At this time, the reverse proxy server and the target server are one server to the outside world. What is exposed is the proxy server address, and the real server IP address is hidden.

2. 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 that nginx will listen on;

server_name is the domain name entered in the browser when accessing nginx. You can directly fill in the IP address. If you want to bind multiple, you can separate them with spaces;

location indicates the URL to be matched when nginx listens to the port. If the URL accessing nginx contains /category/, the proxy is executed.

proxy_pass indicates the target to which nginx will proxy the client's request.

Note the path writing of proxy_pass here. If the path ends without / as above, it means a relative path. Then nginx will not intercept /category/ in the original URL when forwarding the request. For example, if the browser accesses http://localhost:8080/category/findAll, the request address actually sent by nginx is http://localhost/category/findAll.

If the target path of proxy_pass is configured with a / at the end, indicating an absolute path, then nginx will intercept the /category/ in the original URL when forwarding the request. For example, if the browser accesses http://localhost:8080/category/findAll, the request address actually sent by nginx is http://localhost/findAll.

When configuring, you need to decide whether to include / according to your needs, otherwise nginx will always report a 404 error in actual use.

My configuration here contains /category in my backend interface path, so I use a relative path and keep this.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Using nginx forward proxy to implement intranet domain name forwarding process analysis
  • Diagram of the process of implementing direction proxy through nginx
  • Detailed explanation of nginx forward proxy and reverse proxy
  • A universal nginx interface to implement reverse proxy configuration
  • Interview questions about forward proxy and reverse proxy in distributed architecture

<<:  js realizes horizontal and vertical sliders

>>:  MySQL 8.0.18 installation and configuration method graphic tutorial

Recommend

How to use not in to optimize MySql

Recently, when using select query in a project, I...

Briefly describe mysql monitoring group replication

Original text: https://dev.mysql.com/doc/refman/8...

Steps to install MySQL 8.0.23 under Centos7 (beginner level)

First, let me briefly introduce what MySQL is; In...

Mysql master/slave database synchronization configuration and common errors

As the number of visits increases, for some time-...

XHTML introductory tutorial: Web page Head and DTD

Although head and DTD will not be displayed on th...

Detailed comparison of Ember.js and Vue.js

Table of contents Overview Why choose a framework...

DockerToolBox file mounting implementation code

When using docker, you may find that the file can...

Detailed explanation of CSS multiple three-column adaptive layout implementation

Preface In order to follow the conventional WEB l...

PHP-HTMLhtml important knowledge points notes (must read)

1. Use frameset, frame and iframe to realize mult...

Installation process of CentOS8 Linux 8.0.1905 (illustration)

As of now, the latest version of CentOS is CentOS...

SVN installation and basic operation (graphic tutorial)

Table of contents 1. What is SVN 2. Svn server an...

How to choose the format when using binlog in MySQL

Table of contents 1. Three modes of binlog 1.Stat...