When talking about how to configure reverse proxy under Nginx, let us first understand what reverse proxy is. Reverse proxy uses a proxy server to accept Internet connection requests, and then forwards the requests to another server.
Originally, I have never used a reverse proxy, so I have never done it. Just a few days ago, a space on EWSIDC was not allowed to be bound due to a problem with the domain name (imzhaorong.com) BA. You can only bind it through Third-level domain name access provided by the system. But I still want to use the original top-level domain name to access the content of this space. What should I do? Use your VPS as a reverse proxy. Below, let’s look at the detailed process.
First, let’s talk about the general environment. The unBA top-level domain name I use is imzhaorong.com, the third-level domain name provided by EWSIDC is 1e01f.wi.ipc.la, and the VPS I use is Host1Plus’s $1 cloud VPS, which has LNMP installed.
First, we need to resolve the A record of the domain name imzhaorong.com to the IP address of the VPS;
Then, modify the nginx configuration file. In this tutorial, we will download the VPS's nginx.conf to local modification (the file directory is located in /usr/local/nginx/conf/). Let me take a screenshot first:
nginx
The blue part in the picture is the code we added. The reason for the unnecessary step in the picture is mainly to draw attention to the location of adding the code, which should be done before setting up a VPS. I'm in the wrong place. Fortunately, Senior Brother Four gave me some pointers. I'll paste the code below:

server    {
        listen    <x2 >     80;
        server_name   < x2> imzhaorong.com;
        location / {
    <x2 >       proxy_pass               http://1e01f.wi.ipc.la/;
        < x2>   proxy_redirect          off;
             proxy_set_header        X-Real- IP       $remote_addr;
        < x2>   proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
             }
    }

After modification, we first execute: /usr/local/nginx/sbin/nginx -t to check whether the configuration is normal. If it displays: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok < x2>    configuration file /usr/local/nginx/conf/nginx.conf test is successful, then it is normal. Otherwise, modify the configuration according to the error prompt, and the error prompt will be accurate to which line.
Finally execute kill -HUP `cat /usr/local/nginx/logs/nginx.pid` to make the configuration take effect. If your domain name resolution also takes effect, you should be able to access it directly through the top-level domain name.
There are still many uses for reverse proxies. Let’s explore them by ourselves.


Hong Kong/United States/Domestic High Speed ​​VPS

postid
21728

Leave a Reply