Nginx proxy

1. The agent

If you don’t understand this sentence, here’s a real life example: We want to buy a second-hand housing, for example, although we can go to our house, but it is too spend time and effort, and the series of procedures such as house quality testing and transfer also have we to do, say now this society, we find houses, such as house might have appreciated and then how to do? The easiest and quickest way is to find a second-hand housing agency, so we entrusted the agency to find a suitable house for me, as well as the subsequent quality inspection and transfer operations, we just need to choose the house we want, and then pay the money. Agency simply means that if we want to do something, but do not want to do it directly, then we find another person to do it for us. So the intermediary company in this example is the agency service for us, we entrust the intermediary company to help us find a house. Nginx can be used as a proxy for the following protocols, the most used is Http proxy server.

Forward agent

Here I give another example: as we all know, Google is not accessible in China now, so how can we access Google? If our computers’ public IP addresses became U.S. IP addresses, we would be able to access Google. You’re smart. That’s how VPNS come about. When we visit Google, we first connect the VPN server to change our IP address to the US IP address, and then we can visit smoothly. In this case, VPN does forward proxy. The forward proxy server sits between the client and the server. In order to get data from the server, the client sends a request to the proxy server and specifies the target server. The proxy server forwards the data returned by the target server to the client. Here the client is going to do some forward proxy setup. PS: Here is a brief introduction of VPN. In popular terms, VPN is a transfer service. When our computer is connected to VPN, our external IP address will become the public IP address of VPN server. What’s the good of that? For example, the principle of VPN game acceleration, we want to play NETcom area LOL, but the local access is the broadband of telecom, playing netcom area will be more card, then use VPN to change the telecom network into netcom network, and then play netcom area LOL will not card the difference between reverse proxy and forward proxy is: Forward proxy Indicates the proxy client and reverse proxy indicates the proxy server.

The reverse proxy

In fact the client’s agent is no perception, because the client does not require any configuration can access, we only need to send the request to the reverse proxy server, the reverse proxy server to select the target server to get data, returned to the client, at this time the reverse proxy server and the target server is a server, exposure is a proxy server address, The IP address of the real server is hidden.



It can be summed up in one sentence: forward proxy proxy client, reverse proxy server.

2. Nginx reverse proxy

Use the nginx reverse proxy www.nginx123.com to go directly to 127.0.0.1:9090. ① Start a Tomcat and enter 127.0.0.1:9090 in the address bar of the browser

Configuring tomcat Ports

②, modify the local host filewww.nginx123.comMapped to 127.0.0.1

After the configuration is complete, you can access the initial Tomcat interface shown in step 1 at www.nginx123.com:8080.

So how do I just need inputwww.123.comCan jump to the Tomcat initial screen? Nginx’s reverse proxy is used.

Add the following configuration to the nginx.conf configuration file:

server {
        listen       80;
        server_name  www.nginx123.com;

        location / {
            proxy_pass http:/ / 127.0.0.1:9090;index index.html index.htm index.jsp; }}Copy the code

We type www.nginx123.com in the browser and the result is as follows:

(4),

In fact, it is more appropriate to say through the nginx proxy port, the original access is 9090, after the nginx proxy, through port 80 can be accessed.