Troubles with HTTPS

75 views
Skip to first unread message

Igor Mikhalev

unread,
Aug 18, 2017, 3:46:15 AM8/18/17
to ngx-pagespeed-discuss
Hello,

Playing around with pagespeed module, I found that it doesn't work over HTTPS in my case.

I have following configuration: 1st server for serving html, 2nd for serving assets.

Conf files looks like this:

1st:
server {
    listen
80;
    listen
443 ssl;

    server_name dev
.ru;

    ssl_certificate MY_SELF_SIGNED_CERT
;
    ssl_certificate_key MY_SELF_SIGNED_CERT
;

    pagespeed on
;
    pagespeed
FileCachePath ~some_path~/nginxTest/cache/pagespeed;
    pagespeed
Domain *-static.ru;

    location
~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        add_header
"" "";
   
}

    location
~ "^/pagespeed_static/" { }
    location
~ "^/ngx_pagespeed_beacon$" { }

    pagespeed
FetchHttps enable,allow_self_signed,allow_unknown_certificate_authority,allow_certificate_not_yet_valid;

    root
~some_path~/nginxTest/;
   
    charset utf
-8;

    location
/ {
        index index
.html;
   
}
}



2nd:
server {
    listen
80;
    listen
443 ssl;

    server_name dev
-static.ru;

    ssl_certificate MY_SELF_SIGNED_CERT
;
    ssl_certificate_key MY_SELF_SIGNED_CERT
;

    root
~some_path~/nginxTest/;
   
    charset utf
-8;

    pagespeed on
;
    pagespeed
FileCachePath ~some_path~/nginxTest/cache/pagespeed-static;

    location
~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        add_header
"" "";
   
}

    location
~ "^/pagespeed_static/" { }
    location
~ "^/ngx_pagespeed_beacon$" { }

    location
/images/ {
        try_files $uri
=404;
   
}
}


html file:
<!DOCTYPE html>
<html lang="en">
<head>
   
<meta charset="UTF-8">
   
<meta name="viewport" content="width=device-width, initial-scale=1.0">
   
<meta http-equiv="X-UA-Compatible" content="ie=edge">
   
<title>Document</title>
</head>
<body>
   
<img src="https://dev-static.ru/images/test_1.jpg" alt="">
</body>
</html>

With this configuration I only get optimized html, but not the image.

When I use HTTP (change protocol in html), all is working fine.

It also works with

pagespeed MapOriginDomain "http://dev-static.ru" "https://dev-static.ru";

but it is not an appropriate solution, since on production server there is only HTTPS available.

Joshua Marantz

unread,
Aug 18, 2017, 8:28:09 AM8/18/17
to ngx-pagesp...@googlegroups.com
RE HTTPS fetching: is there anything relevant printed in the server logs, or if you fetch your HTML file with ?PageSpeedFilters=+debug ?

Once you get fetching to work in the HTML server, you need to put the FetchHttps directive in the static server as well; so it can fetch its own assets.  However, I'd expect this inconsistency to result in 404s rather than the optimization just not occurring.  But this is the next thing to fix.

I'd also recommend sharing the cache between these servers.  If they are the same physical box it can be the file-cache directory.  If they are on different boxes I'd look into using Redis or Memcached, which are both supported by PageSpeed.  Otherwise you will wind up optimizing the images twice; once on each server.  They need to be fetched and optimized on the HTML server so that the URL can be rewritten with the content-hash.

Another option is to use InPlaceResourceOptimization, in which case you don't need to configure your HTML server at all; just the asset server.  Then your URLs will not be rewritten, but your images can be optimized on the asset server without fetching them.  In that case you will not need to configure HTTPS fetching at all.

-Josh

--
You received this message because you are subscribed to the Google Groups "ngx-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ngx-pagespeed-discuss+unsubscri...@googlegroups.com.
Visit this group at https://groups.google.com/group/ngx-pagespeed-discuss.
For more options, visit https://groups.google.com/d/optout.

Longinos

unread,
Aug 18, 2017, 8:59:22 AM8/18/17
to ngx-pagespeed-discuss
Hi Igor

Perhaps you can try to explicit https

pagespeed Domain https://*-static.ru;

Igor Mikhalev

unread,
Aug 18, 2017, 9:16:06 AM8/18/17
to ngx-pagespeed-discuss
Longinos, thank you, it worked out!

Joshua Marantz, thank you too for help!

пятница, 18 августа 2017 г., 15:59:22 UTC+3 пользователь Longinos написал:
Reply all
Reply to author
Forward
0 new messages