Magento resource problem on CDN Scheme Research, Magento Resource CDN Scheme _php Tutorial

Source: Internet
Author: User

Research on CDN Scheme in Magento resource problem, Magento Resource CDN Scheme


Through the understanding of the Magento, found that the Magento resource files are mainly distributed in media, JS, skin Three folders, the media folder mainly includes the system comes with editors WYSIWYG editor all the resources involved in the editor (Static Blocks , Pages, product Intro, product Images), and Magento's self-generated media resources (including the folder where we allow users to upload files); The skin folder is primarily a template-provided style, picture, JS Resources (in general, we will change the template again to the resources in this folder); JS folder includes Magento official prototype, Varien, Scriptaculous, Mage and other JS libraries and ancillary resources (generally we do not move this folder), All three folders contain static resources (Pictures, JS, CSS, fonts, documents, etc.) that we can CDN.

Through the observation of Magento source code, the website public method Getbaseurl at app/core/mage/core/model/store.php

 Public functionGetbaseurl ($type= Self::url_type_link,$secure=NULL){    $cacheKey=$type. '/' . (Is_null($secure) ? ' Null ': ($secure? ' True ': ' false ')); if(!isset($this->_baseurlcache[$cacheKey])) {        Switch($type) {             CaseSelf::url_type_web:$secure=Is_null($secure) ?$this->iscurrentlysecure (): (BOOL)$secure; $url=$this->getconfig (' web/'). ($secure? ' Secure ': ' unsecure '). '/base_url ');  Break;  CaseSelf::url_type_link:$secure= (BOOL)$secure; $url=$this->getconfig (' web/'). ($secure? ' Secure ': ' unsecure '). '/base_link_url '); $url=$this->_updatepathuserewrites ($url); $url=$this->_updatepathusestoreview ($url);  Break;  CaseSelf::url_type_direct_link:$secure= (BOOL)$secure; $url=$this->getconfig (' web/'). ($secure? ' Secure ': ' unsecure '). '/base_link_url '); $url=$this->_updatepathuserewrites ($url);  Break;  CaseSelf::url_type_skin: CaseSELF::URL_TYPE_JS:$secure=Is_null($secure) ?$this->iscurrentlysecure (): (BOOL)$secure; $url=$this->getconfig (' web/'). ($secure? ' Secure ': ' unsecure '). '/base_ '.$type. ' _url ');  Break;  CaseSelf::url_type_media:$url=$this->_updatemediapathuserewrites ($secure);  Break; default:ThrowMage::Exception(' Mage_core ', Mage::helper (' Core ')->__ (' Invalid base URL type '))); }        if(false!==Strpos($url, ' {{base_url}} ')) {            $BASEURL= Mage::getconfig ()->substdistroservervars (' {{base_url}} '); $url=Str_replace(' {{base_url}} ',$BASEURL,$url); }        $this->_baseurlcache[$cacheKey] =RTrim($url, '/') . '/'; }    return $this->_baseurlcache[$cacheKey];}

The way Url_type_media gets more complicated, we'll see what we've written.

protected function_updatemediapathuserewrites ($secure=NULL,$type= Self::Url_type_media) {    $secure=Is_null($secure) ?$this->iscurrentlysecure (): (BOOL)$secure; $secureStringFlag=$secure? ' Secure ': ' unsecure '; $url=$this->getconfig (' web/').$secureStringFlag. '/base_ '.$type. ' _url '); if(!$this->getconfig (self::xml_path_use_rewrites)&& mage::helper (' core/file_storage_database ')Checkdbusage ()) {        $urlStart=$this->getconfig (' web/').$secureStringFlag. '/base_url '); $url=Str_replace($urlStart,$urlStart. Self::media_rewrite_script,$url); }    return $url;}

We can find that all $type types are always obtained from GetConfig (string configpath), the saved database is stored in the background configuration, General Web, Unsecure & You can configure the modifications in Secure.

Assuming that the Magento whole station as a CDN source server, and then Base_media_url, Base_skin_url, Base_js_url value to the CDN address, is not the resources of the Magento CDN processing it, So I put the local machine on the Magento to test (as the saying goes that the only way to test the truth), because the CDN needs domain name resolution, we temporarily ignore and do not go to the CDN, but we can redirect a new domain name to represent the CDN, such as Hosts Riga two domain names for testing

  127.0. 0.1        magento.yourdomain.com  127.0.  0.1       mage-cdn.yourdomain.com

Nginx in the original magento.yourdomain.com configuration copy and delete the PHP parsing that section to ensure security. By the way, add as many resource types as you can in the resource (not enough to add later)

Restart Nginx, and then login Magento backstage to Base_media_url, Base_skin_url, Base_js_url in the original {{Base_unsecure_url}} are changed to HTTP. mage-cdn.yourdomain.com/, {{Base_secure_url}} are changed to https://mage-cdn.yourdomain.com/and then save settings to re-swipe under Magento cache OK is done.

Open the http://magento.yourdomain.com/, and if you use a different template with a lot of fonts, you might see an error message with cross-domain access:

' https://mage-cdn.yourdomain.com ' ' Access-control-allow-origin ' ' https://magento.yourdomain.com '  not allowed access.

He tells you that Magento's site wants to access some of MAGE-CDN's resources but because there is no access-control-allow-origin head, so we in the Nginx configuration Mage-cdn site resource file access Unified plus Add_header Access-control-allow-origin https://magento.yourdomain.com. Why not use *, if you are very generous to other sites can also cross-domain access to your resources that you used *, I was suggested where to use the binding where, hehe

Then we open the Magento site for a variety of test registration login to upload the background of various editing OK this time we are really done.

Add down is to deploy CDN, landed CDN Service provider, directly set the source site as your magento.yourdomain.com General CDN provide CNAME services, then you generous parsing a cdn.yourdomain.com cname to CDN Service Provider to your address abcd.xxxx.com, the general CDN service providers also provide headers add you can add to this CDN need headers, that is, we need cross-domain requests. And then configure Magento then Blablabla finally you find a way to get CDN Service commercial your CRT certificate. OK, that's fine.

http://www.bkjia.com/PHPjc/1102846.html www.bkjia.com true http://www.bkjia.com/PHPjc/1102846.html techarticle Magento Resource problem on the CDN scheme Research, Magento Resource CDN Scheme through to Magento understanding, found that Magento resource files are mainly distributed in media, JS, skin three folders, media files ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.