Hello!

after update to version 2.19 - gzip is failing for js / css files.
Statusreport:

Adv CSS/JS Agg - gzip	gzip is failing for js files.
The web servers configuration will need to be adjusted. In most cases make sure that the webroots .htaccess file still contains this section "Rules to correctly serve gzip compressed CSS and JS files". Also check in the readme, under Troubleshooting. Certain default web server configurations (nginx) do not gzip HTTP/1.0 requests. If you are using cloudfront you will have to add metadata to the .gz files. There are some other options if using cloudfront. Raw request info:
stdClass Object
(
    [request] => GET /cache/advagg_js/js__-QJyXgjDfMV_ER_vffNtaUp3snZAg8Giiu2zFRZ3n9U__D0kz5oX8INCX1aocfbKa3dnHRnCELXeFcmxZY1yccMI__H-FoKJWreHdHf2gxz0Ot_jHYqRz_qRZJu6TztYwGCD4.js HTTP/1.0
Accept-Encoding: gzip, deflate
Connection: close
Referer: xxx/admin/reports/status
User-Agent: Drupal (+http://drupal.org/)
Host: xxx


    [data] => ...
    [protocol] => HTTP/1.1
    [status_message] => OK
    [headers] => Array
        (
            [content-type] => application/javascript
            [content-length] => 13987
            [connection] => close
            [date] => Mon, 07 Nov 2016 20:16:50 GMT
            [server] => Apache
            [x-content-type-options] => nosniff
            [last-modified] => Sun, 06 Nov 2016 15:25:01 GMT
            [accept-ranges] => bytes
            [cache-control] => max-age=31449600, no-transform, public
            [expires] => Mon, 06 Nov 2017 20:16:50 GMT
        )

    [code] => 200
)

(the same from css)

Greetings
Frank

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Frank.dev created an issue. See original summary.

mikeytown2’s picture

have you ran update.php yet?

Frank.dev’s picture

Yes!

mikeytown2’s picture

Does the error go away if you remove the new .htaccess changes in sites/default/files/advagg_js? Keep only what's in the FilesMatch section.

Frank.dev’s picture

After remove the .htaccess changes - statusreport return:

Adv CSS/JS Agg - Content-Type	

The wrong Content-Type is being sent by your web server.

The web servers configuration will need to be adjusted. Was looking for application/javascript, actually got text/javascript. You might need to apply the drupal core patch located here https://drupal.org/node/2193333#comment-8469991.
mikeytown2’s picture

What version of apache are you using?

Here's the latest patch for core .htaccess
https://www.drupal.org/node/2193333#comment-11460765

Frank.dev’s picture

Apache version 2.4.

After patching the drupal core .htaccess, the error message remains.

Frank.dev’s picture

Soory, error resolved.

When I editing the .htaccess in sites/default/files/advagg_js I had caused a syntax error. I have this corrected and now everything works again (with #4).

Many thanks mikeytown!
Frank

Frank.dev’s picture

Status: Active » Fixed

I think my original problem has been solved. There is, however, another problem, also after the update of this module. But to this I open a new Issue.

mikeytown2’s picture

Status: Fixed » Active

Keeping this open as I would like to code fix for this.

mikeytown2’s picture

What's you exact server environment? I'm also using Apache 2.4. Being able to replicate this behavior would allow for me to get a proper fix in place.

https://httpd.apache.org/docs/2.4/mod/core.html#loglevel
If you're wondering what I'd do, I put this in the apache config
LogLevel trace6
And then issue a single request and see why gzip wasn't returned.

Frank.dev’s picture

I am not using a root server.
I have only "/admin/reports/status" and "/admin/reports/status/php" for information.

mikeytown2’s picture

Example outputs from the php status page. This should help me if you can provide this info

Apache Version 	Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/7.0.12 

Apache Version 	Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.5 

_SERVER["SERVER_SOFTWARE"]	nginx/1.8.1
PHP Version 5.5.24
Frank.dev’s picture

It is just called "Server: Apache" and PHP 7.0.12.

marcolz’s picture

It seems that the rewriting breaks the location of the file and prepends the apache document root to the physical path:

[Wed Nov 09 10:18:04.778559 2016] [core:trace3] [pid 21224] request.c(293): [client 10.100.2.1:44199] request authorized without authentication by access_checker_ex hook: /usr/share/drupal7/sites/default/files/advagg_css/css__FnTpFpH-6tcTOmqJuy5zo3HGSIcbCl6s-XvhyFVxz0Y__iXz2uJeWzlAwQFh7z-P7AWWiccKpz7R1CO7p_W_hCuI__CSmmOfvrcJ37eC8dYBc1UyTLvkzKP-qmPJK65zdsgSs.css.gz, referer: http://test.xxx/drupal7/                   
[Wed Nov 09 10:18:04.778593 2016] [core:info] [pid 21224] [client 10.100.2.1:44199] AH00128: File does not exist: /opt/mmh/www/napps/usr/share/drupal7/sites/default/files/advagg_css/css__FnTpFpH-6tcTOmqJuy5zo3HGSIcbCl6s-XvhyFVxz0Y__iXz2uJeWzlAwQFh7z-P7AWWiccKpz7R1CO7p_W_hCuI__CSmmOfvrcJ37eC8dYBc1UyTLvkzKP-qmPJK65zdsgSs.css.gz, referer: http://test.xxx/drupal7/                                                          

These are the final two lines from a trace6 output. My document root is /opt/mmh/www/napps while drupal runs from /usr/share/drupal7

I am running Ubuntu 14.04 LTS

marcolz’s picture

Removing the new IfModule mod_headers.c block from the .htaccess files in advagg_js and advagg_css fixes it for me in the sense that my JS and CSS files are served again, compressed with gzip.

mikeytown2’s picture

I Coping core; going to try something else
http://cgit.drupalcode.org/drupal/tree/.htaccess#n156

Can you try this?

<IfModule mod_rewrite.c>
  RewriteEngine on
  Options +FollowSymLinks

  # Serve brotli compressed JS files if they exist and the client accepts br.
  RewriteCond %{HTTP:Accept-encoding} br
  RewriteCond %{REQUEST_FILENAME}\.br -s
  RewriteRule ^(.*)\.js $1\.js\.br [QSA]
  RewriteRule \.js\.br$ - [T=application/javascript,E=no-gzip:1]

  <IfModule mod_headers.c>
    <FilesMatch "\.js\.br$">
      # Serve correct encoding type.
      Header set Content-Encoding br
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>

  # Serve gzip compressed JS files if they exist and the client accepts gzip.
  RewriteCond %{HTTP:Accept-encoding} gzip
  RewriteCond %{REQUEST_FILENAME}\.gz -s
  RewriteRule ^(.*)\.js $1\.js\.gz [QSA]
  RewriteRule \.js\.gz$ - [T=application/javascript,E=no-gzip:1]

  <IfModule mod_headers.c>
    <FilesMatch "\.js\.gz$">
      # Serve correct encoding type.
      Header set Content-Encoding gzip
      # Force proxies to cache gzipped & non-gzipped css/js files separately.
      Header append Vary Accept-Encoding
    </FilesMatch>
  </IfModule>
</IfModule>

<FilesMatch "^js__[A-Za-z0-9-_]{43}__[A-Za-z0-9-_]{43}__[A-Za-z0-9-_]{43}.js(\.gz|\.br)?">
  # No mod_headers. Apache module headers is not enabled.
  <IfModule !mod_headers.c>
    # No mod_expires. Apache module expires is not enabled.
    <IfModule !mod_expires.c>
      # Use ETags.
      FileETag MTime Size
    </IfModule>
  </IfModule>

  # Use Expires Directive if apache module expires is enabled.
  <IfModule mod_expires.c>
    # Do not use ETags.
    FileETag None
    # Enable expirations.
    ExpiresActive On
    # Cache all aggregated js files for 52 weeks after access (A).
    ExpiresDefault A31449600
  </IfModule>

  # Use Headers Directive if apache module headers is enabled.
  <IfModule mod_headers.c>
    # Do not use etags for cache validation.
    Header unset ETag
    # Serve correct content type.
    Header set Content-Type application/javascript
    <IfModule !mod_expires.c>
      # Set a far future Cache-Control header to 52 weeks.
      Header set Cache-Control "max-age=31449600, no-transform, public"
    </IfModule>
    <IfModule mod_expires.c>
      Header append Cache-Control "no-transform, public"
    </IfModule>
  </IfModule>
  ForceType application/javascript
</FilesMatch>

mikeytown2’s picture

Thinking I might need to add
Options +FollowSymLinks
To the file. Does that make it work?

mikeytown2’s picture

I can't reproduce this bug locally; can anyone test and see if this fixes the issue for you?

  • mikeytown2 committed f7a1c85 on 7.x-2.x
    Issue #2825530 by mikeytown2: gzip is failing for js / css files
    
mikeytown2’s picture

Status: Needs review » Fixed

#19 has been committed. Please change the status if this is still a problem.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

jrb’s picture

Just wanted to add that we were having the same problem where CSS/JS files were not being compressed after upgrading to 7.x-2.19. We found that just adding "RewriteEngine On" to the .htaccess files in the advagg directories fixed the problem. Then, we found this issue(!). In our case, adding "FollowSymLinks" was not needed. This patch does fix the issue.

For reference, we're running Apache/2.2.15 (Unix) with PHP 7.0.14. The strange thing was that it worked fine running under MAMP (Apache/2.2.31 (Unix), PHP 7.0.12). Not sure what difference might be.

numerabilis’s picture

I tryed to aply this patch but has errors:

/sites/all/modules/advagg$ patch < advagg.patch
patching file advagg.install
Hunk #1 succeeded at 2599 with fuzz 1 (offset 1822 lines).
patching file advagg.missing.inc
Hunk #1 FAILED at 451.
1 out of 1 hunk FAILED -- saving rejects to file advagg.missing.inc.rej

After that my site returns Error 500