Find "object" through nginx proxy“

Keywords: Linux Operation & Maintenance Nginx

preface:

1. Do you want to interact with the front end and back end for the front end and back end separation project? What if you don't learn nginx?

  1. Download an nginx, including Windows version and linux version. You can choose it. Let's take the window version as an example.
  2. After downloading from the Internet, it looks like the ghost below.

    Startup method: double click the exe file or use the command line (feel a little more advanced hahaha)

    Supplement: / usr/local/nginx/sbin/nginx (linux version)
    Kill nginx service command: taskkill /im nginx.exe -f
  3. Verify whether the startup is successful. Visit localhost:80 and the
    *Additional: * if the access is not successful after startup, if you modify the configuration file, there is probably a problem with the configuration file. You can

    By the way, I'll provide you with a pit.

For example, if you proxy the address to Baidu or other public network address, it will appear
The requested URL / was not found on this server.
This address appears, but you are very sure that the address is correct.

Then check your hosts file. The location is


By the way, let me show you the test configuration

The above is the construction of nginx environment. It's just beginning now.

Text:

  1. nginx is a bridge connecting two services. Even if they are thousands of miles apart, they can still be in front of each other. This bridge can be on either side.


It should be mentioned here. It doesn't mean that nginx can only be built on server A. in fact, it has nothing to do with which website you want to visit on that website

2. Install nginx on Linux system

1, Download an nginx website first: http://nginx.org/
2, Prepare dependent environment

#The installation of Nginx depends on the environment, and - y indicates that y is selected by default for all prompts
yum -y install pcre pcre-devel
yum ‐y install zlib zlib‐devel  
yum ‐y install openssl openssl‐devel

#Install gcc compilation environment 
yum -y install gcc

3, Unzip and install

# Enter the home directory and unzip it
tar -zxvf nginx-1.17.5.tar.gz -C /home

# Enter nginx directory
cd nginx-1.17.5

# Compile and install [gcc compilation environment already exists]
./configure
make
make install
# After the installation is successful, an nginx directory will be added under / usr/local

4, Start

#Enter the sbin directory of nginx
cd /usr/local/nginx/sbin

#Start in sbin directory
./nginx
#Stop in sbin directory
./nginx ‐s stop
#Rewrite loading in sbin directory
./nginx ‐s reload

#Open port 80 for external access of Linux. By default, Linux will not open port 80
#To edit iptables files, refer to 4.5
#Check whether there are nginx threads and whether they exist
ps ‐ef | grep nginx

Finally, the access is the same as in the window

Finally, I'll show you my configuration file

# There are only places that need to be changed
server {
        listen       7010;
        server_name  192.168.23.169;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


        location / {
           proxy_pass   http://10.200.76.11:7003;  # Reverse proxy
           # proxy_cookie_domain 10.200.76.11 10.200.77.70; #Modify the domain name in the cookie
		   index  index.html index.htm;
	#	        add_header Access-Control-Allow-Origin http://10.200.77.70;  # When the current end only spans domains without cookie s, it can be*
        add_header Access-Control-Allow-Credentials true;
		add_header Access-Control-Allow-Origin *;


        }
		
		location /zgrm {
           proxy_pass http://10.200.76.11:7003;
        }
		
		location /yssa {
           proxy_pass http://10.200.76.11:7003;
        }
		

Essence of nginx agent:

Before talking about its essence, let me explain the nginx.conf configuration file above.

Don't worry about anything else. It's not the most important part.

Let's talk about the essence of nginx Agency (personal understanding)
The so-called nginx proxy means that nginx is used as a bridge. Through this nginx, we can jump from the ip where nginx is located to any ip address, that is to say, the purpose of changing ip address + port number.

It should be noted that the initial access address must be the ip port where the nginx service is located, and will jump to the specified ip address only when the requested address (the location immediately after the port) is the same as the interception address configured by us.

Special points:

  1. nginx itself is a program and a service. So you can treat it as a service, so we configure it

    Server name: the ip address of the service
    Listen: it's the port that the service listens to. In fact, it's the port number occupied by the service. If you use this port number, it's equivalent to using nginx agent. Otherwise, it's useless if you configure it, but everyone calls it to listen to the port number
  2. Another thing to note is that the so-called nginx proxy depends on what your request address sends. This may not be easy to understand. Let me give an example: when you integrate a system into another system, when the menu jumps, the ip of the sending address should be your nginx address and port number, otherwise you will have cross domain problems, You configure the ip and port of nginx, that is, when you enter nginx, you can jump to the address you specified.

Look at the picture to understand

nginx reverse proxy has finished. What do you don't understand? You can leave a message!!!

Posted by thebay on Thu, 16 Sep 2021 10:34:18 -0700