nginx reverse proxy Introduction

Brief introduction

The server client request, obtaining therefrom the associated set of one or more back-end server (such as a Web server) resources, and then returns the resource to the client, the client will know the IP address of the reverse proxy, I do not know exist in the back of the proxy server.

Module

ngx_http_proxy_module

Examples

location / {
    proxy_pass       http://localhost:8000;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;
}

1. Set the size of the buffer size.

Syntax: proxy_buffer_size size;
Default:    
proxy_buffer_size 4k|8k;
Context:    http, server, location

2. Set the minimum request response is cached

Syntax: proxy_cache_path path [levels=levels] [use_temp_path=on|off] keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number] [manager_sleep=time] [manager_threshold=time] [loader_files=number] [loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number] [purger_sleep=time] [purger_threshold=time];
Default:    —
Context:    http
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=one:10m;

3. When the function is turned on after the buffer in response, without reading all the response, the write buffer reaches a certain size, Nginx will send a response to the client.

Syntax: proxy_cache zone | off;
Default:    
proxy_cache off;
Context:    http, server, location

4. Define the duration of a particular response content cached response code

Syntax: proxy_cache_valid [code ...] time;
Default:    —
Context:    http, server, location
Sets caching time for different response codes. For example, the following directives
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404      1m;

5. Set timeout establishing a connection with the backend server. It should be noted that overtime is generally not be greater than 75 seconds.

Syntax: proxy_connect_timeout time;
Default:    
proxy_connect_timeout 60s;
Context:    http, server, location

6. Define the read-out response from the backend server

Syntax: proxy_read_timeout time;
Default:    
proxy_read_timeout 60s;
Context:    http, server, location

7. Define the transmission request to the backend server timeout

Syntax: proxy_send_timeout time;
Default:    
proxy_send_timeout 60s;
Context:    http, server, location

8. Number of buffer per connection setup

Syntax: proxy_buffers number size;
Default:    
proxy_buffers 8 4k|8k;
Context:    http, server, location

9. When the opening function of the buffer after the response, without reading all the response, the write buffer reaches a certain size, Nginx will send a response to the client until the buffer is less than this value

Syntax: proxy_busy_buffers_size size;
Default:    
proxy_busy_buffers_size 8k|16k;
Context:    http, server, location

After opening the buffer 10. In response to the back-end server functionality temporary file is provided to the data size of each write nginx temporary files

Syntax: proxy_temp_file_write_size size;
Default:    
proxy_temp_file_write_size 8k|16k;
Context:    http, server, location

11 If a situation occurs back-end server, nginx can use the response expired cache

Syntax: proxy_next_upstream error | timeout | invalid_header | http_500 | http_502 | http_503 | http_504 | http_403 | http_404 | http_429 | non_idempotent | off ...;
Default:    
proxy_next_upstream error timeout;
Context:    http, server, location

Guess you like

Origin blog.51cto.com/14074807/2411387