Join the community today
Register Now

Nginx PageSpeed Pagespeed with SSL

Discussion in 'Nginx, PHP-FPM & MariaDB MySQL' started by Moe, Dec 12, 2015.

Tags:
  1. Moe

    Moe New Member

    13
    4
    3
    Dec 4, 2015
    Jupiter
    Ratings:
    +7
    Local Time:
    8:25 PM
    1.9.7
    MariaDB 10.x
    i had my website running amazing just by enabling the pagespeed

    website score jumped from 57 to 93 on pagespeed insights which is wow

    my problem and after searching forums here and on the web i haven't found a way to enable a way to make pagespeed work with SSL in centminmod
    for example : '''
    ModPagespeedFetchHttps enable
    ''''''
    is there a way to do so because that will be great tweak to enable
     
  2. eva2000

    eva2000 Administrator Staff Member

    29,015
    6,582
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,772
    Local Time:
    3:25 AM
    Nginx 1.13.x
    MariaDB 5.5
    • Like Like x 1
  3. Moe

    Moe New Member

    13
    4
    3
    Dec 4, 2015
    Jupiter
    Ratings:
    +7
    Local Time:
    8:25 PM
    1.9.7
    MariaDB 10.x
    Oh i am starting to have a headache, i found what i was searching for @eva2000 but now i had another bigger problem is that nginx -t test failed due to pagespeed.conf problem which i couldn't figure out,when the problem is solved i am going to make a tutorial for amateurs to be easier for new guys at command world :
    This is pagespeed.conf file contents
    Code:
    pagespeed on;
    pagespeed LoadFromFile "https://example.com" "/home/nginx/domains/example.com/public";
    pagespeed MapOriginDomain "http://localhost" "https://www.example.com";
    #######################################################
    # File cache settings
    ######################################
    # needs to exist and be writable by nginx
    
    # pagespeed FileCacheSizeKb          102400;
    # pagespeed FileCacheCleanIntervalMs 3600000;
    # pagespeed FileCacheInodeLimit      500000;
    
    #######################################################
    # By default, ngx_pagespeed adds an X-PageSpeed header with a value of the version of
    # ngx_pagespeed being used. This directive lets you specify the value to use instead:
    # pagespeed XHeaderValue "ngx_pagespeed";
    
    #######################################################
    # let's speed up PageSpeed by storing it in the super duper fast memcached
    # Ensure Memcached server installed http://centminmod.com/memcached.html
    # default install for centmin mod is on port 11211, so localhost:11211 is correct
    # uncomment - remove hash # in front of below 2 lines to enable
    # timeout set at 100 milliseconds
    #  pagespeed MemcachedThreads 1;
    #  pagespeed MemcachedServers "localhost:11211";
    #  pagespeed MemcachedTimeoutUs 100000;
    
    #######################################################
    ## https://developers.google.com/speed/pagespeed/module/admin#virtual-hosts-and-stats
    ######################################
    # pagespeed UsePerVhostStatistics on;
    
    #######################################################
    ## 1.7.30.1 beta defaults
    ######################################
    pagespeed PreserveUrlRelativity on;
    pagespeed MaxCombinedCssBytes -1;
    pagespeed ImageResolutionLimitBytes 16777216;
    pagespeed EnableFilters inline_google_font_css;
    
    #######################################################
    ## 1.6.29.3 beta defaults
    ######################################
    pagespeed AvoidRenamingIntrospectiveJavascript on;
    pagespeed ImageInlineMaxBytes 3072;
    pagespeed CssImageInlineMaxBytes 0;
    pagespeed MaxInlinedPreviewImagesIndex -1;
    pagespeed MinImageSizeLowResolutionBytes 3072;
    
    #######################################################
    ## ngx_pagespeed filters settings below ##
    ######################################
    
      # show half the users an optimized site, half the regular site
      # change UA-XXXXXXXXXX-1 to your GA unique id
      # uncomment - remove hash # in front of below 5 lines to enable
    #  pagespeed RunExperiment on;
    #  pagespeed AnalyticsID UA-XXXXXXXXXX-1;
    #  pagespeed ExperimentVariable 1;
    #  pagespeed ExperimentSpec "id=1;percent=50;level=CoreFilters;enabled=collapse_whitespace,remove_comments;";
    #  pagespeed ExperimentSpec "id=2;percent=50";
      # Filter settings
      # filters outlined at http://ngxpagespeed.com/ngx_pagespeed_example/
      pagespeed RewriteLevel CoreFilters;
      pagespeed EnableFilters collapse_whitespace,remove_comments;
    
      # make_google_analytics_async
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-make-google-analytics-async
    #  pagespeed EnableFilters make_google_analytics_async;
    
      # inline_css
      # https://developers.google.com/speed/pagespeed/module/filter-css-inline
    #   pagespeed EnableFilters inline_css;
    #   pagespeed CssInlineMaxBytes 2048;
    
      # prioritize_critical_css
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-prioritize-critical-css
    #   pagespeed EnableFilters prioritize_critical_css;
    
      # move_css_to_head
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-to-head
      pagespeed EnableFilters move_css_to_head;
    
      # move_css_above_scripts
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-above-scripts
    #  pagespeed EnableFilters move_css_above_scripts;
    
       combine_css
       https://developers.google.com/speed/docs/mod_pagespeed/filter-css-combine
    #  pagespeed EnableFilters combine_css;
    
       # Uncomment this if you want to prevent mod_pagespeed from combining files
       # (e.g. CSS files) across paths
       #
    #  pagespeed CombineAcrossPaths off;
    
    # combine_javascript
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-js-combine
      # pagespeed EnableFilters combine_javascript;
      #pagespeed MaxCombinedJsBytes 122900;
    
      # extend_cache
       https://developers.google.com/speed/docs/mod_pagespeed/filter-cache-extend
    pagespeed EnableFilters extend_cache;
    
      # rewrite_css
       https://developers.google.com/speed/docs/mod_pagespeed/filter-css-rewrite
      pagespeed EnableFilters rewrite_css;
    
      # rewrite_javascript
       https://developers.google.com/speed/docs/mod_pagespeed/filter-js-minify
      pagespeed EnableFilters rewrite_javascript;
    
      # inline_preview_images
      # https://developers.google.com/speed/pagespeed/module/filter-inline-preview-images
    #  pagespeed EnableFilters inline_preview_images;
    
       lazyload_images
       https://developers.google.com/speed/docs/mod_pagespeed/filter-lazyload-images
    pagespeed EnableFilters lazyload_images;
    
      # rewrite_images
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-image-optimize
    #  pagespeed EnableFilters rewrite_images;
    #   pagespeed DisableFilters rewrite_images;
    #   pagespeed DisableFilters recompress_images;
    #   pagespeed DisableFilters convert_png_to_jpeg;
    #   pagespeed DisableFilters extend_cache_images;
    #  pagespeed EnableFilters convert_png_to_jpeg;
    #  pagespeed EnableFilters convert_jpeg_to_webp;
    #  pagespeed EnableFilters convert_to_webp_lossless;
    
      # sprite_images
       https://developers.google.com/speed/docs/mod_pagespeed/filter-image-sprite
    pagespeed EnableFilters rewrite_css,sprite_images;
    
      # insert_dns_prefetch
      # https://developers.google.com/speed/docs/mod_pagespeed/filter-insert-dns-prefetch
    #  pagespeed EnableFilters insert_dns_prefetch;
    
      # InPlaceResourceOptimization
      # https://developers.google.com/speed/pagespeed/module/system#ipro
      # Enabled by default as of 1.9.32.1
    #  pagespeed InPlaceResourceOptimization off;
    
    #######################################################
    
    Here is my Website example.com.ssl.conf settings
    Code:
    # Centmin Mod Getting Started Guide
    # must read http://centminmod.com/getstarted.html
    # For SPDY SSL Setup
    # read http://centminmod.com/nginx_configure_https_ssl_spdy.html
    
    # redirect from www to non-www  forced SSL
    # uncomment, save file and restart Nginx to enable
    # if unsure use return 302 before using return 301
    server {
       server_name example.com www.example.com;
        return 302 https://$server_name$request_uri;
    
    }
    
    server {
      listen 443 ssl http2;
      server_name example.com www.example.com;
    
      ssl_dhparam /usr/local/nginx/conf/ssl/example.com/dhparam.pem;
      ssl_certificate   /usr/local/nginx/conf/ssl/example.com/example.com-unified.crt;
      ssl_certificate_key  /usr/local/nginx/conf/ssl/example.com/example.com.key;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # mozilla recommended
      ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA:!CAMELLIA:!DES-CBC3-SHA;
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header  X-Content-Type-Options "nosniff";
      #add_header X-Frame-Options DENY;
      #spdy_headers_comp 5;
      ssl_buffer_size 1400;
      ssl_session_tickets on;
     
      # enable ocsp stapling
      resolver 8.8.8.8 8.8.4.4 valid=10m;
      resolver_timeout 10s;
      ssl_stapling on;
      ssl_stapling_verify on;
      ssl_trusted_certificate /usr/local/nginx/conf/ssl/example.com/example.com-trusted.crt; 
    
    # ngx_pagespeed & ngx_pagespeed handler
    include /usr/local/nginx/conf/pagespeed.conf;
    include /usr/local/nginx/conf/pagespeedhandler.conf;
    include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/example.com/log/access.log combined buffer=256k flush=60m;
      error_log /home/nginx/domains/example.com/log/error.log;
    
      root /home/nginx/domains/example.com/public;
    
      # prevent access to ./directories and files
      location ~ (?:^|/)\. {
       deny all;
      }
    
    include /usr/local/nginx/conf/wpsupercache_example.com.conf; 
    
      location / {
    
      # Enables directory listings when index file not found
      #autoindex  on;
    
      # for wordpress super cache plugin
      try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
      # Wordpress Permalinks
      #try_files $uri $uri/ /index.php?q=$uri&$args; 
    
      }
    
    location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        auth_basic "Private";
        auth_basic_user_file /home/nginx/domains/example.com/htpasswd_wplogin;   
        include /usr/local/nginx/conf/php-wpsc.conf;
    }
    
    location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        include /usr/local/nginx/conf/php-wpsc.conf;
    }
    
      include /usr/local/nginx/conf/wpsecure_example.com.conf;
      include /usr/local/nginx/conf/php-wpsc.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    
    And here are the results
    Code:
    [root@b~]# systemctl status nginx.service -l
    nginx.service - SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse proxy and IMAP/POP3 proxy server
       Loaded: loaded (/etc/rc.d/init.d/nginx)
       Active: active (running) since Fri 2015-12-11 15:38:13 UTC; 22h ago
      Process: 24518 ExecStop=/etc/rc.d/init.d/nginx stop (code=exited, status=0/SUCCESS)
      Process: 24526 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)
    Main PID: 24533 (nginx)
       CGroup: /system.slice/nginx.service
               ├─24533 nginx: master process /usr/local/sbin/nginx -c /usr/local/nginx/conf/nginx.con
               ├─24534 nginx: worker process
               └─24535 nginx: worker process
    
    Dec 11 15:38:13 site9.example.com nginx[24526]: Starting nginx: nginx: [warn] conflicting server name "         example.com" on 0.0.0.0:80, ignored
    Dec 11 15:38:13 site9.example.com nginx[24526]: nginx: [warn] conflicting server name "www.example.com"          on 0.0.0.0:80, ignored
    Dec 11 15:38:13 site9.example.com nginx[24526]: [  OK  ]
    Dec 11 15:38:13 site9.example.com systemd[1]: Started SYSV: Nginx is an HTTP(S) server, HTTP(S) reverse          proxy and IMAP/POP3 proxy server.
    [root@b~]# nano -c  /usr/local/nginx/conf/conf.d/example.com.ssl.conf
    [root@b~]# nano -c  /usr/local/nginx/conf/pagespeed.conf
    [root@b~]# nginx -t
    nginx: [emerg] unknown directive "combine_css" in /usr/local/nginx/conf/pagespeed.conf:105
    nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
    [root@b~]# nano -c  /usr/local/nginx/conf/conf.d/example.com.ssl.conf
    
    i am really lost
     
    Last edited: Dec 13, 2015
  4. eva2000

    eva2000 Administrator Staff Member

    29,015
    6,582
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,772
    Local Time:
    3:25 AM
    Nginx 1.13.x
    MariaDB 5.5
  5. eva2000

    eva2000 Administrator Staff Member

    29,015
    6,582
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +9,772
    Local Time:
    3:25 AM
    Nginx 1.13.x
    MariaDB 5.5
    and uncommented wrong line
    Code:
       combine_css
       https://developers.google.com/speed/docs/mod_pagespeed/filter-css-combine
    #  pagespeed EnableFilters combine_css;
    change to
    Code:
       #combine_css
       #https://developers.google.com/speed/docs/mod_pagespeed/filter-css-combine
      pagespeed EnableFilters combine_css;
    same with a few others you uncommented the https line in pagespeed.conf, leave it commented out

    incorrect
    Code:
      # extend_cache
       https://developers.google.com/speed/docs/mod_pagespeed/filter-cache-extend
    pagespeed EnableFilters extend_cache;
    
      # rewrite_css
       https://developers.google.com/speed/docs/mod_pagespeed/filter-css-rewrite
      pagespeed EnableFilters rewrite_css;
    
      # rewrite_javascript
       https://developers.google.com/speed/docs/mod_pagespeed/filter-js-minify
      pagespeed EnableFilters rewrite_javascript;
    
    correct
    Code:
      # extend_cache
       # https://developers.google.com/speed/docs/mod_pagespeed/filter-cache-extend
    pagespeed EnableFilters extend_cache;
    
      # rewrite_css
       # https://developers.google.com/speed/docs/mod_pagespeed/filter-css-rewrite
      pagespeed EnableFilters rewrite_css;
    
      # rewrite_javascript
       # https://developers.google.com/speed/docs/mod_pagespeed/filter-js-minify
      pagespeed EnableFilters rewrite_javascript;
    
    you have a few more like this with mistaken uncomments on the https line linking to documentation for the specific filters