Page 1 of 1

[HOWTO] Serve static content from a cookieless domain in NGINX

Posted: Thu Jun 01, 2017 4:34 pm
by SS88
Hey guys,

Solving that Google Pagespeed issue as well as others...

Very simply one here. For all those that know what you're doing it's a one-liner:

Code: Select all

fastcgi_hide_header "Set-Cookie";
In EVERY template (perhaps Vesta set this has default?) in the folder /usr/local/vesta/data/templates/web/nginx/php-fpm

Change:

Code: Select all

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
        }
To

Code: Select all

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
            fastcgi_hide_header "Set-Cookie";
        }
For example this file now looks like this: /usr/local/vesta/data/templates/web/nginx/php-fpm/wordpress.tpl

Code: Select all

server {
    listen      %ip%:%web_port%;
    server_name %domain_idn% %alias_idn%;
    root        %docroot%;
    index       index.php index.html index.htm;
    access_log  /var/log/nginx/domains/%domain%.log combined;
    access_log  /var/log/nginx/domains/%domain%.bytes bytes;
    error_log   /var/log/nginx/domains/%domain%.error.log error;

    location / {

        location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js)$ {
            expires     max;
            fastcgi_hide_header "Set-Cookie";
        }

        location ~ [^/]\.php(/|$) {
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            if (!-f $document_root$fastcgi_script_name) {
                return  404;
            }

            fastcgi_pass    %backend_lsnr%;
            fastcgi_index   index.php;
            include         /etc/nginx/fastcgi_params;
        }
    }

    error_page  403 /error/404.html;
    error_page  404 /error/404.html;
    error_page  500 502 503 504 /error/50x.html;

    location /error/ {
        alias   %home%/%user%/web/%domain%/document_errors/;
    }

    location ~* "/\.(htaccess|htpasswd)$" {
        deny    all;
        return  404;
    }

    include     /etc/nginx/conf.d/phpmyadmin.inc*;
    include     /etc/nginx/conf.d/phppgadmin.inc*;
    include     /etc/nginx/conf.d/webmail.inc*;

    include     %home%/%user%/conf/web/nginx.%domain%.conf*;
}

Re: [HOWTO] Serve static content from a cookieless domain in NGINX

Posted: Wed Sep 20, 2017 4:50 am
by RobertSP
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|css|js|eot|otf|woff|woff2|ttf|ogg)$ {
expires max;
fastcgi_hide_header "Set-Cookie";
}
for better optimization

Re: [HOWTO] Serve static content from a cookieless domain in NGINX

Posted: Sat Mar 17, 2018 2:22 am
by rhyker2u
thanks for the snippets!