Correct configuration to fix CORS issue with CloudFront

back to snippest | Comment | Share

If you are using CloudFront for hosting static assets and having trouble with the CORS which prevents the icons from displaying properly on your website, in this post, I am going to show how to resolve this issue.

In case you are having an issue with woff2 or woff or any static fonts, here is the solution.

two steps to solve CORS issue on CloudFront are:

Make change to Nginx or Apache configuration to add Access-Control-Allow-Origin: * to the response data. You can take a look at some guides: and

Add a behavior in CloudFront distribution, remember to whitelist the Origin header

but first you need to have a cdn account with cloud front:

Second. Register new distribution with amazon cloud front by following the default steps

Third assign a CName, make sure you have email enabled to verify your cdn custom name:

you need to enable cross origin by using php and .htaccess file

Complete example of my htaccess using WPFC

Enable Origin Using your cloudfront account:

we recommend using
HTTP Headers by Dimitar Ivanov wordpress plugin and configure the settings as following

in other cases and if you are using nginx, we recommend the following
1-Edit common_http.conf

2-Add the origin to cloudfront behavior
3-set Invalidations inside cloudfront, eg:

in case you are using WP-Optimize wordpress plugin you need to configure both the cookies caching and pages caching correctly as following

Cookies caching

Thats all,

if you need paid support on this, message me via whatsapp

About the Author

Hi! I'm Ahmad. I have a degree in Computer Science from Birzeit University and you might call me a bit of computer geek. I am the Founder of Greenbackend Turnkey Solutions a leading Cloud and Hosting Company in the Middle East, Also I am the Founder of Ahmad Naser Turnkey Solutions in Harvey, LA, USA. I'm comfortable with a large range of languages and techniques. After implementing enterprise applications using Salesforce and Siebel CRM for 3 years and with professional experience in building websites, cloud apps, iOS apps, Unity games, Android mobile apps and educational games for 8 years. I decided to share my technical knowledge with people all over the world to benefit from my experience and build their own careers specially because I am a real world example with over 20 successful apps on Google Play Store, Asset Store and Apple Store, So your success is mine and I want to help you reach your goals step by step exactly as I do. I'm passionate about teaching people about technologies, so from time to time I gave courses online and in learning centers and teach beginners and professionals on many technologies and development frameworks. One of my greatest goals in life is growing the next generation of software professionals and to keep teaching programming at every opportunity I get. I can't wait to help you experience the achievement and financial freedom that having a deep understanding of technology brings. So why not start learning to design & develop now by joining our epic Unity 3D professional 2d game development course? See you soon! Ahmad