reverse proxy
Hide server information -> ensure the security of the internal network, usually use the reverse proxy as the public network access address, and the web server is the internal network, that is, configure the external network to access the internal network of the web server through nginx
example
Baidu's website is: http://www.baidu.com,
Now I pass my server address http://192.168.1.102
To visit Baidu's address
And the access address is your own server ip or domain name address, at this time we can configure reverse proxy through Nginx to achieve ~
simple configuration
server {
listen 80;
server_name 192.168.1.102;# server address or bound domain name
location / { # All paths after accessing port 80 are forwarded to the ip configured by proxy_pass
root /usr/share/nginx/html;
index index.html index.htm;
proxy_pass http://www.baidu.com; # Configure the ip address and port number of the reverse proxy [Note: http:// or https:// should be added to the url address]
}
}
complex configuration
Access different server addresses according to different suffixes
Copy apache-tomcat into two copies, one is tomcat8081, the other is tomcat8082, the process is as follows
cp -r apache-tomcat tomcat8081
cp -r apache-tomcat tomcat8082
Then modify the port number in the server.xml configuration in tomcat8081 through a remote connection
8081
Then change the index.jsp in the ROOT folder in the webapps folder in tomact8081 to the following, and you can see that the content entered below is 8081
<html lang="en"> <head> <title><%=request.getServletContext().getServerInfo() %></title> <link href="favicon.ico" rel="icon" type="image/x-icon" /> <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /> <link href="tomcat.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>tomcat8081index.jsp<h1> </body> </html>
Then change the index.jsp in the ROOT folder in the webapps folder in tomact8082 to the following, and you can see that the content entered below is 8082
<html lang="en"> <head> <title><%=request.getServletContext().getServerInfo() %></title> <link href="favicon.ico" rel="icon" type="image/x-icon" /> <link href="favicon.ico" rel="shortcut icon" type="image/x-icon" /> <link href="tomcat.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>tomcat8082index.jsp<h1> </body> </html>
Then start tomcat8081 and tomcat8082, start as follows
/root/tomcat8081/bin/startup.sh
/root/tomcat8082/bin/startup.sh
Access these two addresses separately, you can access successfully
Then we configure the host file in the local computer to become as follows
windows/system32/drivers/etc
Then configure the nginx.conf configuration file in the conf folder in the nginx server, remember to restart the nginx server after configuration
At this time, when visiting www.sina.com, it will visit the host file, and then it will find the linux server corresponding to the ip 47.91.248.236, and then the default port of www.sina.com is 80, so visit www.sina .com, you will find the following upstream tomcat1, and then the following upstream tomcat1 will go to server 47.91.248.236:8081, and you will find the tomcat server at port 8081, and because the default access page of upstream tomcat1 is index.jsp , so it will visit the index.jsp page of the tomcat server on port 8081 (that is, http://47.91.248.236:8081/index.jsp)
At this time, when you visit www.huohu.com, you will visit the host file, and then you will find the linux server corresponding to the ip 47.91.248.236, and then the default port of www.huohu.com is 80, so visit www.huohu .com, you will find the following upstream tomcat2, and then the following upstream tomcat2 will go to server 47.91.248.236:8082, and you will find the tomcat server at port 8082, and because the default access page of upstream tomcat2 is index.jsp , so it will visit the index.jsp page of the tomcat server on port 8082 (that is, http://47.91.248.236:8082/index.jsp)
user root; worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; 47.91.248.236:8081; } server { listen 80; server_name www.sina.com; location / { proxy_pass http://tomcat1; #Configure the default access page, here you will access the index in the index.jsp file in tomcat1 index.jsp; } } #Configure www.houhu.com: 80 corresponds to the server listening port upstream tomcat2 { server 47.91.248.236:8082; } server { listen 80; server_name www.houhu.com; location / { proxy_pass http:/ /tomcat2; #Configure the default access page, here you will access the index.jsp file in tomcat2 index index.jsp; } } }
Then we visit www.sina.com
At this time, the tomcat server corresponding to tomcat8081 is accessed
Then we visit www.huohu.com
At this time, the tomcat server corresponding to tomcat8082 is accessed
Nginx implements load balancing