Monday, November 19, 2018

nginx - Enable Leverage Browser Caching

If you are trying to enable Leverage Browser Caching for your site in nginx and it still shows not enabled in Google PageSpeed Insights and GTmetrix.

Solution :
1) Edit file /etc/nginx/sites-enabled/default
2) Add line
expires 365d;
in your virtualhost under "server {" above "location / {"
3) Restart nginx


Example :
server {
    listen 80;
    server_name yourdomainname.com;
    expires 365d;
    client_max_body_size 128M;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:8080;
        proxy_connect_timeout       600;
        proxy_send_timeout          600;
        proxy_read_timeout          600;
        send_timeout                600;
        add_header X-Frame-Options SAMEORIGIN; 
        add_header X-Content-Type-Options nosniff; 
        add_header X-XSS-Protection "1; mode=block"; 
        proxy_hide_header X-Powered-By;
        server_tokens off;
        autoindex off;
        etag off;
    }

}

No comments:

Post a Comment