nginx를 리버스 프록시 소개

간략한 소개

서버 클라이언트 요청 (예 : 웹 서버로) 하나 이상의 백 엔드 서버의 관련 설정 이로부터 얻는 자원 한 다음 클라이언트에 리소스를 반환, 클라이언트는 역방향 프록시의 IP 주소를 알 수 나는 프록시 서버의 뒷면에 존재 알고하지 않습니다.

모듈

ngx_http_proxy_module

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

1. 버퍼 크기를 설정한다.

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

최소 요청 응답이 캐시 2.

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. 기록 버퍼가 특정 크기에 도달 Nginx의 클라이언트에게 응답을 전송한다.

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

4. 특정 응답 콘텐츠 캐시 응답 코드의 지속 시간을 정의

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. 제한 시간. 이는 초과 일반적 75초보다 크게되는 것이 아니다.

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

6. 백엔드 서버에서 판독 응답을 정의

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

제 백엔드 서버 타임 아웃에 송신 요구를 정의

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

연결 설정에 따라 버퍼의 번호 8

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

9. 모든 응답을 읽지 않고 반응 후 완충액 개구 기능, 기록 버퍼가 특정 크기에 도달하면, 버퍼가이 값 이하가 될 때까지의 Nginx 클라이언트에게 응답을 보낼

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

각각의 데이터 사이즈에 제공되는 백엔드 서버 기능 임시 파일에 응답하여 상기 버퍼 (10)를 개방 한 후 Nginx에 임시 파일을 작성

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

11 상황이 백 엔드 서버를 발생하는 경우, nginx를 응답 캐시 만료 사용할 수 있습니다

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

추천

출처blog.51cto.com/14074807/2411387