How to configure nginx and tomcat achieve reverse proxy?

What is a reverse proxy
         is usually a proxy server, the proxy only for internal network to the Internet connection request, the client must specify the proxy server, and would have to be sent directly to http requests on the Web server sends to the proxy server, by the proxy server It initiates a request to a web server on the Internet, and ultimately to the client access to the Internet. This is known as forward proxy, usually directly called agent.

         Reverse proxy (Reverse Proxy) refers to the proxy server to accept connection requests on the internet, and then forwards the request to the server on the internal network, and the results obtained from the server back to the requesting client on the internet connection, At this point the external proxy server on the performance of a reverse proxy server.

 Nginx only request forwarding, multiple back-end http server to provide services, the role of nginx is to put forward the request to the back of the server, it forwards the request to decide who handles.

As shown below:

 

 

Nginx reverse proxy configuration
scenarios
         two tomcat service by nginx reverse proxy, this example uses three virtual machines for testing,

         nginx server: 192.168.78.132

         tomcat1 server: 192.168.78.134

    tomcat2 server: 192.168.78.135

As shown below:

 

 

Environmental ready
  1. Two tomcat server, I used here is to use apache-tomcat-7.0.57 version, start tomcat on 192.168.78.134 and 192.168.78.135 virtual machine.

  2. Nginx server, the previously installed, ip address is: 192.168.78.132

  3. Modify the contents of the webapps two tomcat / ROOT / index.jsp, the use of two services tomcat1 and tomcat2 Home display different content.

  4. Specify aaa.test.com and bbb.test.com correspond 192.168.78.132 virtual machine host file: Modify window hosts file: (C: \ Windows \ System32 \ drivers \ etc)

192.168.78.132 aaa.test.com
192.168.78.132 bbb.test.com

nginx reverse proxy configuration

According to your needs in the top of the file nginx.conf reverse proxy, as follows:

# Tomcat1 configure a proxy server that is 
upstream tomcat_server1 { 
    Server 192.168.78.134:8080 ; 
} 
 
# configure a proxy server tomcat2 i.e. 
upstream tomcat_server2 { 
    Server 192.168.78.135:8080 ; 
} 
 
# configure one virtual server 
Server { 
    the listen 80 ; 
    server_name aaa.test .com; 
    LOCATION / { 
        request # aaa.test.com domain name forwarded to all that is on tomcat_server1 tomcat1 service 
        proxy_pass HTTP: // tomcat_server1; 
 
        # welcome page, find the page from left to right order 
        index index.jsp index.html index.htm; 
 
    } 
} 
 
Server { 
    the listen 80; 
    Server_name bbb.test.com; 
    LOCATION / { 
        requests # bbb.test.com domain forwarding to all the services tomcat_server2 i.e. tomcat2 
        proxy_pass HTTP: // tomcat_server2; 
 
        index the index.jsp index.html index.htm; 
    } 
}

test

Separate visits aaa.test.com, bbb.test.com test reverse proxy.

 

 

As can be seen from the above screenshot:

Requesting access aaa.test.com by nginx proxy access tomcat1,

Requesting access bbb.test.com by nginx proxy access tomcat2.

 

Finally
over, put nginx and how to configure tomcat achieve reverse proxy finished. While more steps, but the operation is relatively simple.

Guess you like

Origin www.cnblogs.com/qwlscn/p/11489694.html