nginx優化-使用gzip壓縮
阿新 • • 發佈:2018-11-12
使用gzip壓縮
放置區塊:http
此壓縮功能與早期Apache服務的mod_deflate壓縮功能很相似,Nginx的gzip壓縮功能 依賴於ngx_http_gzip_module模組,預設已安裝
在主配置檔案nginx.conf中配置
[[email protected] conf]# cat /application/nginx/conf/nginx.conf worker_processes 2; worker_cpu_affinity 0101 1010; error_log logs/error.log; #配置Nginx worker程序最大開啟檔案數 worker_rlimit_nofile 65535; user www www; events { #單個程序允許的客戶端最大連線數 worker_connections 20480; #使用epoll模型 use epoll; } http { include mime.types; default_type application/octet-stream; #sendfile on; #keepalive_timeout 65; #訪問日誌配置 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; #虛擬主機 include /application/nginx/conf/extra/www.conf; include /application/nginx/conf/extra/blog.conf; include /application/nginx/conf/extra/bbs.conf; include /application/nginx/conf/extra/edu.conf; include /application/nginx/conf/extra/phpmyadmin.conf; include /application/nginx/conf/extra/status.conf; #nginx優化---------------------- #隱藏版本號 server_tokens on; #優化伺服器域名的散列表大小 server_names_hash_bucket_size 64; server_names_hash_max_size 2048; #開啟高效檔案傳輸模式 sendfile on; #減少網路報文段數量 #tcp_nopush on; #提高I/O效能 tcp_nodelay on; #連線超時 時間定義 預設秒 預設65秒 keepalive_timeout 60; #讀取客戶端請求頭資料的超時時間 預設秒 預設60秒 client_header_timeout 15; #讀取客戶端請求主體的超時時間 預設秒 預設60秒 client_body_timeout 15; #響應客戶端的超時時間 預設秒 預設60秒 send_timeout 25; #上傳檔案的大小限制 預設1m client_max_body_size 8m; #nginx與php之間FastCGI 相關引數調優 #時間超時設定 fastcgi_connect_timeout 240; fastcgi_send_timeout 240; fastcgi_read_timeout 240; #緩衝/快取設定 fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_temp_path /data/ngx_fcgi_tmp; fastcgi_cache_path /data/ngx_fcgi_cache levels=2:2 keys_zone=ngx_fcgi_cache:512m inactive=1d max_size=40g; #使用gzip壓縮 gzip on; gzip_min_length 1k; gzip_buffers 4 32k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/css text/xml application/javascript text/plain application/x-javascript application/xml; gzip_vary on; }