Example of a nginx
config file for use with WordPress:
server
{
server_name .{DOM}.{TLD};
access_log /var/log/nginx/{DOM}.{TLD}.access.log;
error_log /var/log/nginx/{DOM}.{TLD}.error.log;
root /home/sites/{DOM}.{TLD}/www;
# The index directive is set in /etc/nginx/nginx.conf.
# It is not necessary to enable it here.
# index index.php index.html index.htm;
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
# use fastcgi for all php files
location ~ .php$
{
# To use a socket instead of a port, place a comment before the next line
# and remove the comment from the second line.
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/var/run/php5-fpm/{DOM}.{TLD}.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to apache .htaccess files
location ~ /.ht
{
deny all;
}
}
Background information
- Nginx configuration for WordPress, by António P. P. Almeida