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

Questions regarding the Web Server
Apache + Nginx, Nginx + PHP5-FPM
Forum rules
Before creating a new topic or reply on the forum you should fill out additional fields "Os" and "Web" in your profile section.
In case of violation, the topic can be closed or response from the support will not be received.
SS88
Posts: 306
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*;
}

RobertSP
Posts: 3
Joined: Mon Aug 01, 2016 6:40 am

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

Postby RobertSP » Wed Sep 20, 2017 4:50 am

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


Return to “Web Server”



Who is online

Users browsing this forum: No registered users and 4 guests