nginx server block configuration with cache – ubuntu 16.04

server {
    listen 80;
    listen [::]:80;

    root /var/www/yourdomain.com;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name yourdomain.com www.yourdomain.com;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }    

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    }

    location ~ /\.ht {
        deny all;
    }

    etag on;
    expires 7d;
    if_modified_since before;

    gzip on;
    gzip_vary on;
    gzip_comp_level 6;
    gzip_types text/plain text/xml image/svg+xml # text/html in core already.
    application/rss+xml application/atom+xml application/xhtml+xml
    text/css application/json application/x-javascript
    application/font-otf application/font-ttf;

    location ~* \.(?:ttf|ttc|otf|eot|woff|woff2|css|js)$ {
      add_header Access-Control-Allow-Origin *;
    }

    location ~* \.php$ {
      fastcgi_param WP_NGINX_CONFIG done;
    }    
}

Leave a Reply

Your email address will not be published. Required fields are marked *