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

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
SS88
Posts: 298
Joined: Thu Nov 19, 2015 12:40 pm

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

Postby SS88 » Thu Jun 01, 2017 4:34 pm

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*;
}

Return to “Web Server”



Who is online

Users browsing this forum: No registered users and 9 guests