nginx.confを公開してみる

私はウェブサーバーにnginxを導入しています。nginxはそもそも高速なサーバーとして有名ですが、サイト表示のパフォーマンスを上げるために色々カスタマイズを行っています。そこで、私が使っている設定を公開してみようかなと思います。

一応この設定でPageSpeed Insightsのチェックでは最もスコアが良かったはず。多分。もちろんユーザーなどは適宜書き換えてくださいね。

user www-data;
worker_processes auto;
worker_rlimit_nofile 100000;
pid /run/nginx.pid;

events {
worker_connections 2048;
multi_accept on;
use epoll;
}

http {

##
# Basic Settings
##

sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 10;
client_header_timeout 10;
client_body_timeout 10;
reset_timedout_connection on;
send_timeout 10;

limit_conn_zone $binary_remote_addr zone=addr:5m;
limit_conn addr 100;

types_hash_max_size 2048;
server_tokens off;

# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;
charset UTF-8;

##
# Logging Settings
##

access_log /var/log/nginx/access.log;
log_format main ‘$remote_addr – $remote_user [$time_local] “$request” ‘
‘”$status” $body_bytes_sent “$http_referer” ‘
‘”$http_user_agent” “$http_x_forwarded_for” “$gzip_ratio”‘;
error_log /var/log/nginx/error.log;

##
# Gzip Settings
##

gzip on;
gzip_disable “msie6”;

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 8 8k;
gzip_min_length 1000;
gzip_http_version 1.0;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

open_file_cache max=100000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;

##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##

#include /etc/nginx/naxsi_core.rules;

##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##

#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;

##
# Virtual Host Configs
##

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

主な変更点はログの形式とgzip圧縮の設定だと思います。worker関係はかなり多めにとっているので、マシンスペックによって調整してくださいね。ログの形式は、apacheと同じ形式にしてるんだったかな…?webalizerで解析できる形式で保存させています。webalizer使っていない方はこんなことしなくておっけー。(accesslogとerrorlogの間の三行削除)

gzip圧縮は有効にしておくと、ページを圧縮して転送量を減らし、表示速度を改善することが出来ます。PageSpeed Insightsのスコアに関わってくるので、適用してみてもいいのではないでしょうか。

細かい解説がなくて申し訳ないですが、紹介だけしておきます。



コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

日本語が含まれない投稿は無視されますのでご注意ください。(スパム対策)