Environment:
Nginx1: 192.168.68.41
2017at1: 192.168.68.43
Tomcat2: 192.168.68.45
Nginx is installed in many tutorials on the Internet. I installed nginx with yum.
Configure nginx:
Vim/etc/nginx/CONF. d/Default. conf
Content:
# Compresses the data stream gzip on; gzip_min_length 1000; gzip_types text/plain text/CSS application/X-JavaScript; # sets the Server list of Server Load balancer # The weigth parameter indicates the weight, the higher the weight, the higher the probability of being allocated to upstream Hello {server 192.168.68.43: 8080 Weight = 1; server 192.168.68.45: 8080 Weight = 1;} server {# listening port 80 listen 80; SERVER_NAME localhost; # Set the address location/nginxstatus {stub_status on; access_log on; auth_basic "nginxstatus"; auth_basic_user_file htpasswd;} # match the address ending with JSP, tomcat's webpage file ends with JSP location/{Index. JSP; proxy_pass http: // hello; # Set a proxy here, which is the same as upstream's name # The following are some reverse proxy configurations that can delete proxy_redirect off; # The backend web server can use X-forwarded-for to obtain the user's real IP address proxy_set_header host $ host; proxy_set_header X-real-IP $ remote_addr; proxy_set_header X-forwarded-for $ scheme; client_max_body_size 10 m; # maximum number of single-file bytes allowed for client requests client_body_buffer_size 128 K; # maximum number of bytes of client requests buffered by the buffer proxy proxy_connect_timeout 300; # nginx and backend server connection timeout (proxy connection timeout) proxy_send_timeout 300; # backend server data return time (proxy sending timeout) proxy_read_timeout 300; # after successful connection, response time of the backend server (proxy receiving timeout) proxy_buffer_size 4 K; # Set the buffer size proxy_buffers 4 32 K for the proxy server (nginx) to save user header information; # proxy_buffers buffer, set proxy_busy_buffers_size 64 K; # proxy_temp_file_write_size 64 K under high load (proxy_buffers * 2) proxy_temp_file_write_size 64 K; # Set the cache folder size, greater than this value, will be uploaded from upstream server }}
Start:
Nginx
Exit:
Nginx-s quit
After nginx is started, access http: // 192.168.68.41/test/
Will be navigated to http: // 192.168.68.43: 8080/test/and http: // 192.168.68.45: 8080/test/
This achieves load balancing and avoids spof.
Nginx reverse proxy configuration example