Nginx reverse proxy configuration example

Source: Internet
Author: User
Tags nginx reverse proxy

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.