Nginx 설정 최적화 편
Gzip
gzip on;
, 1K ,
gzip_min_length 1k;
gzip 。4 16k 16k , 16k 4 。
gzip_buffers 4 16k;
gzip_http_version 1.1;
1~9。1 ,9 。 cpu。
gzip_comp_level 2;
MIME , "text/html" 。 ,Nginx gzip javascript、 , gzip_types MIME ,
text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
http , vary , , , 。 , , HTTP , 。
gzip_vary on;
curl gzip
curl -I -H "Accept-Encoding: gzip, deflate" "http://www.qcloud.com/example/"
fastCGI 관리자 설정
FastCGI 、 、 。levels 。fastcgi_cache , , 2:2 256*256 ,keys_zone ,cache ( nginx , ),inactive ,max_size , fastcgi_cache fastcgi_temp_path fastcgi_cache_path, , 0.8.9 , 。
fastcgi_cache_path /usr/local/nginx/fastcgi_cache levels=1:2 keys_zone=TEST:10m inactive=5m;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp_path
FastCGI
fastcgi_connect_timeout 300;
FastCGI , FastCGI 。
fastcgi_send_timeout 300;
FastCGI , FastCGI 。
fastcgi_read_timeout 300;
FastCGI , fastcgi_buffers , 1 16k , , ( 1k), fastcgi_buffers , fastcgi_buffers
fastcgi_buffer_size 16k;
FastCGI , , php 256k, 16 16k , 256k, 256k fastcgi_temp , , , php , 256k 16 16k, 4 64k 64 4k, , , 32k, 4 64k 1 64k , 64 4k 8 4k , 16 16k 2 16k , 。
fastcgi_buffers 16 16k;
fastcgi_buffers 。
fastcgi_busy_buffers_size 16k;
fastcgi_temp_path , fastcgi_buffers 。
fastcgi_temp_file_write_size 16k;
FastCGI 。 , CPU , 502 。 , 。
fastcgi_cache TEST;
, 200,302 ,301 1 , 1 。
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_path inactive , , 5 1 , 。
fastcgi_cache_min_uses 1;
。
fastcgi_cache_use_stale error timeout invalid_header http_500;
nginx 버퍼 최적화 (역방향 에이전트 사용) 버퍼 에 대해 서 는 주로 버퍼 크기 를 합 리 적 으로 설정 하고 하 드 디스크 에 버퍼 가 있 을 때 proxybuffering 이 닫 히 면 nginx 는 백 엔 드 에서 받 은 응답 내용 을 클 라 이언 트 에 즉시 전송 합 니 다. 매번 받 는 크기 는 proxy 입 니 다.buffer_size 의 크기, 이렇게 하면 효율 이 틀림없이 비교적 낮 을 것 이다.proxy_buffering 을 사용 할 때 사용 할 프 록 시 버퍼 가 너무 큽 니 다.이것 은 에이전트 가 지원 할 수 있 는 최대 병렬 연결 수 를 제한 하 는 메모 리 를 먹 어 버 릴 수 있 습 니 다.
_
proxy_connect_timeout 20s;
# , ( )
proxy_read_timeout 20s;
_
proxy_send_timeout 20s;
, proxy_buffer_size proxy_buffers 2 ,Linux 8k。
proxy_temp_file_write_size 64k;
proxy_temp_path proxy_cache_path
proxy_cache_path
levels ;levels=1:2
keys_zone
inactive
max_size , , 。
proxy_temp_path /xxx/proxy_temp_path;
proxy_cache_path
/xxx/proxy_cache_path
levels=1:2
keys_zone=cache_one:2000m
inactive=1d
max_size=5m;
proxy_buffering ,nignx , ( , )。 , off, proxy_buffers proxy_busy_buffers_size 。 proxy_buffering , proxy_buffer_size 。
proxy_buffering on;
, 。 , 4k 。
proxy_buffer_size 4k;
proxy_buffers , 。 ,Linux 4k。 proxy_buffers 。 number*size。
proxy_buffers 8 1M; //
proxy_buffer 4 32k; //
proxy_busy_buffers_size , proxy_buffers proxy_buffer_size 。nginx ,
( proxy_busy_buffers_size , proxy_buffers 2 ),
, 。
proxy_busy_buffers_size 2M; //
proxy_busy_buffers_size 64k; //
proxy_max_temp_file_size proxy_buffers , . , Nginx Proxy , 。 , buffers ( _temp_path ), , . proxy_max_temp_file_size .
proxy_max_temp_file_size 0;
Nginx 설정 설명
user www www;
( CPU )
worker_processes 8;
, ! 8 ,8 ( 16 ,00000001 00000001 00000010 CPU , , )
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000;
nginx , (ulimit -n) nginx , nginx , ulimit -n( Linux ) 。
worker_rlimit_nofile 204800;
epoll I/O ,
use epoll;
, nginx worker_processes * worker_connections。
worker_connections 204800;
client_max_body_size 300m;
client_body_buffer_size 128k;
,1
client_body_timeout 600;
header ,1
client_header_timeout 600;
, ,max , ,inactive 。
open_file_cache max=65535 inactive=60s;
。
open_file_cache_valid 80s;
inactive , ,
open_file_cache_min_uses 1;
URI request header 400
#start
servername --
server_names_hash_bucket_size 128k;
128k large_client_header_buffers 。 4 ,128k , 4 128k。 8k。,
large_client_header_buffers 4 128k;
#end
, , 1k, 1k, 。 getconf PAGESIZE
client_header_buffer_size 2k;
sendfile() 。sendfile() TCP socket ( )。Pre-sendfile 。 read() ,write() 。sendfile() OS 。 ,sendfile() read() write() 。
sendfile on;
nginx , 。 , , , 。tcp_nopush sendfile on 。
tcp_nopush on;
nginx , -- ,
, 。
tcp_nodelay keepalive 。
tcp_nodelay on;
http , 60s, , , 。 ! http nginx , nginx ! , , , , 。 , NGINX 。 , 。
keepalive_timeout 60;
, ,max , ,inactive 。
open_file_cache max=204800 inactive=20s;
open_file_cache inactive , ,
, , inactive ,
open_file_cache_min_uses 1;
。
open_file_cache_valid 30s;
web server(Nginx) , 。
server_tokens off;
,FastCGI , php-fpm FastCGI, :
, 60 。
60
。
65535
。
65535
참고 문장http://blog.csdn.net/mary881225/article/details/70173907 http://www.vpsee.com/2009/06/64mb-vps-optimize-nginx/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.