I'm looking for the recommended way of how to configure Nginx server to run Craft.
Currently, I use the following configuration, it works, but I don't know if it could be better:
server {
listen 80;
server_name example.com;
root /home/vagrant/craft/public;
index index.html index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/example.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~* (?:^|/)\. {
deny all;
}
location ~* (?:\.(?:bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$ {
deny all;
}
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
try_files $uri /index.php?$query_string;
expires -1;
access_log /var/log/nginx/example.com-access.log;
}
location ~* \.(?:rss|atom)$ {
try_files $uri /index.php?$query_string;
expires 1h;
add_header Cache-Control "public";
}
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
try_files $uri /index.php?$query_string;
expires 1M;
add_header Cache-Control "public";
}
location ~* \.(?:css|js)$ {
try_files $uri /index.php?$query_string;
expires 1y;
add_header Cache-Control "public";
}
location ~* \.(?:ttf|ttc|otf|eot|woff)$ {
try_files $uri /index.php?$query_string;
expires 1M;
add_header Cache-Control "public";
}
}