"Web" Nginx reverse proxy and load balancing

Source: Internet
Author: User
Tags nginx reverse proxy nginx load balancing

Reverse Proxy

The reverse proxy method refers to a proxy server that accepts connection requests on the Internet, then forwards the request to a server on the internal network and returns the results from the server to the client requesting the connection on the Internet, Reverse. At this point the proxy server appears as a reverse proxy server externally.

The Nginx reverse proxy workflow is as follows:
  

Nginx set the reverse proxy as follows, in the Nginx configuration file configuration
  

1 server {2 #侦听的80端口3 Listen;4 server_name localhost;5     6 Location /{7  8 Proxy_pass http://127.0.0.1:81; #在这里设置一个代理9 #以下是一些反向代理的配置可删除Ten proxy_redirect off; One #后端的Web服务器可以通过X-forwarded-for Get the user real IP A proxy_set_header Host $host; - proxy_set_header x-real-ip $remote _addr; - proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; the client_max_body_size 10m; #允许客户端请求的最大单文件字节数 - client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数 - proxy_connect_timeout; #nginx跟后端服务器连接超时时间 (proxy connection timeout) - proxy_send_timeout; #后端服务器数据回传时间 (proxy send timeout) + proxy_read_timeout; #连接成功后, back-end server response time (proxy receive timeout) - proxy_buffer_size 4k; #设置代理服务器 (nginx) buffer size for saving user header information + proxy_buffers 4 32k; #proxy_buffers缓冲区, the average web page is below 32k, so set A proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2) at proxy_temp_file_write_size 64k; #设定缓存文件夹大小, greater than this value, will be transmitted from the upstream server -     } -}
Load Balancing

Load balancing, the English name is load Balance, which means that it is distributed across multiple operating units for execution, such as Web servers, FTP servers, enterprise critical application servers, and other mission-critical servers, to work together to accomplish tasks.

The upstream module is required for Nginx load balancing. Work as follows:
  

The Nginx configuration is as follows:

1 Upstream my_server_pool{2 server 192.168.7.7:80 weight=1 max_fails=2 fail_timeout=30s;3 server 192.168.7.8:80 weight=1 max_fails=2 fail_timeout=30s;4 server 192.168.7.9:80 weight=1 max_fails=2 fail_timeout=30s;5     }6     7 server {8 Listen;9 server_name localhost;Ten Location /{ One Proxy_pass Http://my_server_pool; A  - proxy_set_header Host $host; - proxy_set_header x-real-ip $remote _addr; the proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; -     } -}

"Web" Nginx reverse proxy and load balancing

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.