Nginx reverse proxy

Source: Internet
Author: User
Tags nginx reverse proxy
Overview

Nginx (engine X) is a lightweight web server, reverse proxy server, and e-mail (IMAP/POP3) proxy server.

Reverse proxy and forward proxy

Forward proxy

Similar to the stepping stone host, the proxy accesses external resources;

A forward proxy is a server located between the client and the origin server. To get content from the origin server, the client sends a request to the proxy and specifies the target (original server ), then the proxy transfers the request to the original server and returns the obtained content to the client. The client must make some special settings to use the forward proxy.

Reverse Proxy

The Proxy Server accepts connection requests from the Internet, forwards the requests to the servers on the internal network, and returns the results obtained from the server to the Client Requesting connection from the Internet, in this case, the proxy server acts as a server.

  1. To ensure Intranet security, you can use reverse proxy to provide WAF to prevent Web attacks.
  2. Server Load balancer optimizes website load through reverse proxy servers

              

 

Use
Nginx-s stop: Quickly shut down nginx, may not save relevant information, and quickly terminate the web service. Nginx-s quit smoothly closes nginx, stores relevant information, and ends the Web service on schedule. Nginx-s reload is reloaded due to nginx-related configuration changes. Nginx-s reopen re-open the log file. Nginx-C filename specifies a configuration file for nginx to replace the default one. Nginx-t does not run, but only tests the configuration file. Nginx checks the syntax of the configuration file and tries to open the file referenced in the configuration file. Nginx-V displays the nginx version. Nginx-V displays the nginx version, compiler version, and configuration parameters.

 

Server Load balancer

Nginx provides two load balancing policies: built-in policies and extension policies. Built-in policies include round robin, Weighted Round Robin, and IP hash. Expand the policy.

Nginx. conf configuration

HTTP {# sets the MIME type, which is determined by mime. the type file defines include/etc/nginx/mime. types; default_type application/octet-stream; # Set the log format access_log/var/log/nginx/access. log; # Set the Server list of Server Load balancer upstream load_balance_server {# The weigth parameter indicates the weight value. The higher the weight value, the higher the probability of being allocated. Server 192.168.1.11: 80 Weight = 5; server 192.168.1.12: 80 Weight = 1; server 192.168.1.13: 80 Weight = 6;} # HTTP server {# Listen on port 80 listen 80; # define using www.xx.com to access SERVER_NAME www.helloworld.com; # Server Load balancer Request Location/{root/root; # define the default website root directory location of the Server Index index.html index.htm; # define the name of the home index file proxy_pass http: // load_balance_server; # requests are redirected to the server list defined by load_balance_server # The following are some reverse proxy configurations (optional) # proxy_redirect off; proxy_set_header host $ host; proxy_set_header X-real-IP $ remote_addr; # the backend web server can use X-forwarded-for to obtain the user's real IP proxy_set_header X-forwarded-for $ remote_addr; proxy_connect_timeout 90; # nginx and backend server connection timeout (proxy connection timeout) proxy_send_timeout 90; # backend server data return time (proxy sending timeout) proxy_read_timeout 90; # 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, the client_max_body_size 10 m will be uploaded from the upstream server; # maximum number of single-file bytes allowed by the client; client_body_buffer_size 128 K; # maximum number of bytes requested by the buffer proxy to buffer the client }}}


The status of each device in upstream:

Down indicates that the server before a ticket is not involved in the load
The default weight value is 1. The larger the weight value, the larger the load weight.
Max_fails: the default number of failed requests is 1. If the maximum number of failed requests is exceeded, an error defined by the proxy_next_upstream module is returned.
Fail_timeout: The pause time after max_fails failed.
Backup: Requests the backup machine when all other non-Backup machines are down or busy. Therefore, this machine is under the least pressure.

Nginx reverse proxy

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.