「Linux/nginx/パフォーマンス向上」の版間の差分
提供: 初心者エンジニアの簡易メモ
| (同じ利用者による、間の14版が非表示) | |||
| 行1: | 行1: | ||
==静的ファイル圧縮== | ==静的ファイル圧縮== | ||
| − | vi /etc/nginx/ | + | 圧縮は個別confでなく全体で設定したほうがわかりやすいと思う。 |
| + | |||
| + | vi /etc/nginx/nginx.conf | ||
http { | http { | ||
gzip on; | gzip on; | ||
gzip_http_version 1.0; | gzip_http_version 1.0; | ||
| + | gzip_comp_level 6; #(1-9) | ||
| + | gzip_proxied any; | ||
| + | gzip_vary on; | ||
gzip_types text/plain | gzip_types text/plain | ||
text/xml | text/xml | ||
| 行13: | 行18: | ||
application/javascript | application/javascript | ||
application/x-javascript | application/x-javascript | ||
| − | application/x-httpd-php; | + | application/x-httpd-php |
| + | application/json | ||
| + | text/javascript; | ||
gzip_disable "MSIE [1-6]\."; | gzip_disable "MSIE [1-6]\."; | ||
gzip_disable "Mozilla/4"; | gzip_disable "Mozilla/4"; | ||
| − | + | gzip_buffers 16 8k; | |
| − | gzip_buffers | + | |
gzip_min_length 1100; | gzip_min_length 1100; | ||
このさき略 | このさき略 | ||
} | } | ||
| + | |||
| + | gtmatrixの"Specify a Vary: Accept-Encoding header"対応はgzip_varyを追加すればok | ||
==ブラウザのキャッシュを活用する方法== | ==ブラウザのキャッシュを活用する方法== | ||
| + | vi /etc/nginx/conf.d/sample1.localhost.conf | ||
| + | location ~* \.(txt|xml)$ { | ||
| + | fastcgi_pass_header "X-Accel-Expires"; | ||
| + | expires 2d; | ||
| + | } | ||
| + | location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff)$ { | ||
| + | fastcgi_pass_header "X-Accel-Expires"; | ||
| + | expires 365d; | ||
| + | } | ||
| + | location ~* \.(html|htm)$ { | ||
| + | fastcgi_pass_header "X-Accel-Expires"; | ||
| + | expires 2h; | ||
| + | } | ||
| + | |||
| + | ==ブラウザのキャッシュを活用する方法(apache連携編)== | ||
location ~* \.(txt|xml)$ { | location ~* \.(txt|xml)$ { | ||
fastcgi_pass_header "X-Accel-Expires"; | fastcgi_pass_header "X-Accel-Expires"; | ||
expires 2d; | expires 2d; | ||
| + | root /var/www/zend/sample1/public; | ||
| + | index index.html; | ||
} | } | ||
| − | location ~* \.(jpg|gif|png|swf|css|js|inc|ico|pdf|flv|gz)$ { | + | location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff)$ { |
fastcgi_pass_header "X-Accel-Expires"; | fastcgi_pass_header "X-Accel-Expires"; | ||
expires 365d; | expires 365d; | ||
| + | root /var/www/zend/sample1/public; | ||
| + | index index.html; | ||
} | } | ||
location ~* \.(html|htm)$ { | location ~* \.(html|htm)$ { | ||
fastcgi_pass_header "X-Accel-Expires"; | fastcgi_pass_header "X-Accel-Expires"; | ||
| − | expires | + | expires 2h; |
| + | root /var/www/zend/sample1/public; | ||
| + | index index.html; | ||
} | } | ||
2016年7月12日 (火) 16:09時点における最新版
静的ファイル圧縮
圧縮は個別confでなく全体で設定したほうがわかりやすいと思う。
vi /etc/nginx/nginx.conf
http {
gzip on;
gzip_http_version 1.0;
gzip_comp_level 6; #(1-9)
gzip_proxied any;
gzip_vary on;
gzip_types text/plain
text/xml
text/css
application/xml
application/xhtml+xml
application/rss+xml
application/atom_xml
application/javascript
application/x-javascript
application/x-httpd-php
application/json
text/javascript;
gzip_disable "MSIE [1-6]\.";
gzip_disable "Mozilla/4";
gzip_buffers 16 8k;
gzip_min_length 1100;
このさき略
}
gtmatrixの"Specify a Vary: Accept-Encoding header"対応はgzip_varyを追加すればok
ブラウザのキャッシュを活用する方法
vi /etc/nginx/conf.d/sample1.localhost.conf
location ~* \.(txt|xml)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 2d;
}
location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 365d;
}
location ~* \.(html|htm)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 2h;
}
ブラウザのキャッシュを活用する方法(apache連携編)
location ~* \.(txt|xml)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 2d;
root /var/www/zend/sample1/public;
index index.html;
}
location ~* \.(jpg|jpeg|gif|png|swf|css|js|inc|ico|pdf|flv|gz|woff)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 365d;
root /var/www/zend/sample1/public;
index index.html;
}
location ~* \.(html|htm)$ {
fastcgi_pass_header "X-Accel-Expires";
expires 2h;
root /var/www/zend/sample1/public;
index index.html;
}
公式パラメータ説明 http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires
参照
http://www.mk-mode.com/octopress/2013/01/18/nginx-gzip-compress/
