Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

Cache Issue faced due to bad request from Amzon CDN Cloud front

Avatar

Level 2

Hi All, 

I would need help in resolving the for the below issue, 

Currently, We are using CQ 5.6 and today our site was down due to the following issue.

We have used CDN for caching. Last night, there was the request from CDN to IHS Webserver which has the dispatcher. Request was something like (/static/version/main.min.css/fonts/abcfont.woff) from amazon cloud front IP. "Main.min.css" is the main file for our website look and feel. 

Due to the slash (/) appended with "main.min.css/" in the request dispatcher cached as the directory (main.min.css) instead of css file alone. This resulted in failed download of correct CSS file which resulted in misalignment of pages without correct styling ad lead to poor customer experience. CDN also would have suffered to get hold of the correct CSS file as it was not in IHS server. 

As a Short term fix, we manually cleared the cache directory in IHS dispatchers. The dispatchers cached and served the CSS files correctly this time and webpages started rendering fine.

In IHS logs we observed, 

2016/11/15 01:24:38 192.168.218.5 - - 192.168.218.5 GET /static/version8/css/main.min.css/fonts/abc-glyph.woff HTTP/1.1 - 200 45473 - 0 15158 "Amazon CloudFront" "-" 80 www.abc.com
2016/11/15 01:24:38 192.168.218.6 54.239.166.154 - 192.168.218.6 GET /static/version8/css/main.min.css/fonts/abc-Bold.woff HTTP/1.1 - 200 45473 - 0 15904 "Amazon CloudFront" "-" 80 www.abc.com
2016/11/15 01:24:38 192.168.218.5 - - 192.168.218.5 GET /shop/DisplayProductFlyout?productId=22244 HTTP/1.1 - 200 54209 0 0 136391 "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36" "-" 80 www.abc.com
2016/11/15 01:24:38 192.168.218.6 54.239.166.154 - 192.168.218.6 GET /static/version8/css/main.min.css/fonts/abc-Light.svg%23font HTTP/1.1 - 200 45473 - 0 14588 "Amazon CloudFront" "-" 80 www.abc.com

Hi All,

 

Could you please post the possible fixes that I can apply to avoid reoccurrence.

9 Replies

Avatar

Community Advisor

You could put rules in Dispatcher or Cloudfront to handle that sort of request correctly.

Do you have mod_rewrite enabled on your Apache Dispatcher instance?

if so, you could define a custom 404 page

ErrorDocument 404 /incorrect_request_for_path.html

and add following rule:

RewriteRule (.*)(main.min.css/) http://domain.com/incorrect_request_for_path.html?path=$2 [R=301,L]

Then any request that is invalid(as it contains /) could be pointed to custom 404 page.

Alternatively, cloudfront rules for the same can be setup to avoid serving css/

Regards,

Peter

Avatar

Level 2

Hi Peter,

 

Thank You so much for your reply.

Could you be able to post one complete example? Thanks

Avatar

Level 2

So with my case, It should be added like this?

ErrorDocument 404 /incorrect_request_for_path.html (Some link which is 404 in site)

and add the following rule:

RewriteRule (.*)(main.min.css/) http://domain.com/incorrect_request_for_path.html(same path as above)?path=$2 [R=301,L]

Then any request that is invalid(as it contains /) could be pointed to custom 404 page.

Alternatively, CloudFront rules for the same can be setup to avoid serving CSS/

 

How can we set it up in Cloudfront rules and where we need to set this up? 

These things will really help me peter. Thanks..

Avatar

Level 2

Thanks, Peter and this is done on dispatcher.any configuration file. Am I right?

Avatar

Community Advisor

First option:

# configure the minimal setting for the dispatcher # the main configuration is read from the 'DispatcherConfig' file. <IfModule disp_apache2.c> # location of the configuration file. eg: 'conf/dispatcher.any' DispatcherConfig /etc/apache2/conf/dispatcher.any # location of the dispatcher log file. eg: 'logs/dispatcher.log' DispatcherLog    /var/log/apache2/dispatcher.log # log level for the dispatcher log # 0 Errors # 1 Warnings # 2 Infos # 3 Debug DispatcherLogLevel 3 # if turned to 1, the dispatcher looks like a normal module # since build 5210, this setting has no effect, since it used to crash # apache if set to 0. DispatcherNoServerHeader 1 # if turned to 1, request to / are not handled by the dispatcher # use the mod_alias then for the correct mapping DispatcherDeclineRoot 0 </IfModule> <Directory /> <IfModule disp_apache2.c> # enable dispatcher for ALL request. if this is too restrictive, # move it to another location SetHandler dispatcher-handler ModMimeUsePathInfo On </IfModule> RewriteEngine On RewriteRule (.*)(main.min.css/) - [R=404]
Options FollowSymLinks AllowOverride None </Directory> # document root for web server DocumentRoot "/data/dispatcher/cache"

You can enrich it further with error handling via the suggested route of ErrorDocument. Please note that in the example provided paths are specific to my machine. It is unlikely to work straight in your Dispatcher via crude copy/paste unless we have exactly same paths or you change paths accordingly to your machine.

For best way to configure CloudFront consult your AWS folks - Second option. Adobe Managed Services would be the good way to help you configure your CDN as they also run on AWS.

Regards,

Peter

Avatar

Level 2

Hi Peter, 

Coud you please let me where exatcly to add the recommended rewrite rule. Whether it should go to dispacter.conf or dispactcher.any?

RewriteEngine On

RewriteRule (.*)(main.min.css/) - [R=404]

Avatar

Community Advisor

Hi Anilven,

Normally, you would put it in the dispatcher.conf before the end of <Directory> tag. The location of the rewrite rule and configfile.conf might vary depending on how you have configured your dispatcher as both of these properties can be changed, or other rewrite rules you have added.

As per OOTB setup, rewrite rule needs to go in the dispatcher.conf before the closing <Directory> tag, similar to the one in the example provided.

Please remember that you can check the validity of your config by running apachectl configtest or httpd -t both are equivalent.

Regards,

Peter