Block IP with Varnish

Blocking certain IPs from visiting the website may be necessary for some reason, and with appache or nginx, the webmaster can achieve this easily, while for varnish, which acts before nginx or appache, one need to configure varnish correctly.

At the beginning of the default.vcl, put the below codes:

acl unwanted {
"69.60.116.97";
"69.60.116.197";
}

And in the sub vcl_recv entry, put the code:


sub vcl_recv {
if (client.ip ~ unwanted) {
error 410;
}

restart your varnish and everything is done now.

Magento Mobilized

As advised in my previous post, I failed to implement the mobile theme on a magento-powered shopping site when turning on the varnish. After checking the default.vcl carefully, I just found there was an entry for sub design_exception at the end of the file, and after replacing this blank entry with the correct one, varnish began to work, so does the mobile theme.

Below is the full entry for the sub design_exception, which is put just behind the entry of sub vcl_hash.


sub vcl_hash {
hash_data(req.url);
if (req.http.host) {
hash_data(req.http.host);
} else {
hash_data(server.ip);
}
if (!(req.url ~ "^/(media|js|skin)/.*\.(png|jpg|jpeg|gif|css|js|swf|ico)$")) {
call design_exception;
}
return (hash);
}

sub design_exception {
if (req.http.User-Agent ~ " iPhone|iPod|BlackBerry ") {
hash_data("theme_iphone");
}
}

Magento Mobile Theme

Before I got a Motorola ME525+ I always thought that the only thing mobile phone can do is making phone call, and after that, I had to admit I was totally wrong. The smartphone can do so much thing that I didn’t expected, especially when it comes to the online ecommerce. So, I decided to make my magento-powered shopping site mobiled, but how?

As I used the theme from Joomlart, and as advised by the developer, their themes are compatitble with such mobile devices as iphone and android-powered ones, so I changed the configuration and disable or cleared the cache, which include the cache by magento itself, xcache and varnish, and yes, it does work, while the only thing that I don’t like is the bad display for the catalog page.

What you need to do is to add the design exception in the system configuration, and the matched expression can include

iPhone|iPod|BlackBerry|Palm|Googlebot-Mobile|Mobile|mobile|mobi|Windows Mobile|Safari Mobile|Android|Opera Mini.

I searched Magento connect and found another one called silver, which does work fine, and I thought thing was done before I turn on the cache.

But when all the caches are on, varnish caches everything, either the visits from the desktop or the one from mobile devices, the result is: the pages visited via mobile device would also display on the desktop and vice versa. And I googled again and found this article and made the changes to the default.vcl, and to my surprise, it didn’t work and the varnish failed to restart.

So I can only delete the mobile exception at this stage and continue the search for a solution.

Small Leaf Ebony Sandalwood Chinese Erhu

Fast and Best Magento Theme

Before launching my magento store, I made a lot of study about the theme as I knew it is a crucial part for the busienss business, and I finally made my choice with templates-master and paid them more for modification works.

Compared with their original design package, the modified one obviously had some flaws when it comes to perfomance issues, for example, no image combination using css sprites, but anyway, I thought it ok and until the new magento version released and I had to upgrade as the google base was not supported by the old version.

This time I had to find a new theme as I wouldn’t pay extra money for the modification every time magento has new release, even templates-master provides free life upgrade service, but this doesn’t apply to a customized one. After numnous comparision, I decided to go ahead with Joomart as I had enough experience with their Joomla template. The bad things that Joomlart’s theme are the lack of optimization, which I think can be gained via other implementation such as xcache and varnish.

The final installation of joomlart did provide a fresh look, but still I am searching for a good theme that is fast and good enough, so far just failed to locate one.

Moving to Linode Newark Datacenter

My original datacenter is in Fremont as I don’t have much idea about the importance of location on website’s speed, I just found that peope here in China said the one in Fremont is fast enough, so I followed suit and signed in there.

Yes, the speed proved to be fast over the years and until recently that I realized that I may need a change of the location as there are many visitors from European countries, and to balance that, I think the location in Newark would be much better as my websites just aims at ASIA-PACIFIC region except Australia and New Zealand.

Moving such datacenter is really easy enough, opening a ticket with Linode and got response within 5 minutes, power off and click the migration button, waiting for about 4 hours and everything was done smoothly, not necessary to backup.

The only thing I forgot to do is to change the DNS setting as the IP changed too after such move, of course, you can change it immediately and it takes max. 15 minutes to take effect.

Now the performance for European countries does improved.

The only thing that may be not good is the “worse” performance when being tested with Ashley Schroder’s magento testing tools at http://www.magespeedtest.com/.

Before the moving:

Before th Moving

After the moving:

After th Moving

Anyway, still it is a acceptable one.

Finally, Magento began to fly!

I struggled with the relatively low performance of magento on vps with nginx+php-fpm+mysql+xcache installation, and alrways tried to get a performance boost from the available free stuffs, I don’t intend to pay bucks for the paid extentions.

And as advised in earlier posts, I jumped on the wagon with varnish, which seems to promise some improvements, but the result was just bad: not working at all.

I knowed I should have made something wrong with the configuration, and today is a working Monday and I have enough time to dig into the issues. Both nginx and varnish started smoothly and what left was indeed the correct configuration.

1) Changed the nginx to listen on port 8080 instead of the original 80 port, which can be easily done via modifying the nginx.conf file as below;

listen 8080;

2) Changed the varnish default.vcl file as below, of course, what you need to do is just to have a copy available online;

backend default {
.host = "127.0.0.1";
.port = "8080";
}

3) Changed the varnish configuration as below;

DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
# -u varnish -g varnish \
-S /etc/varnish/secret \
-s malloc,256M"

The final line depends on your vps ram size (a quarter of that would be ok).

4) Finally, install the free PageCache powered by Varnish extention from magento connect, and change the server port in the magento configuration system page to 80.

5) Restart nginx+php-fpm+varnish, and performance boosted.

After upgrade, Magento slows down

I had to upgrade my magento installation as the 1.4 version didn’t support the google shopping content, and although there were many problems during the upgrade, still I made it work finally.

Another thing I implemented after the upgrade was the addition of social media extention, when people browses the product details page, such social medias as facebook, twitter and google plus would appear just under the product title.

I know this would slow down the speed, but I had to do it as such social media are indeed so important these days for marketting.

Before the social media extension installation, I already found that the performance loose, and I think one main reason may be the fact that after enabling compilation, the checkout out page just turned into a blank page.

I had expected a performance boost after the upgrade, but indeed it turned to be a loss.

The server I used already applied nginx+php-fpm+xcache+mysql+xcache, and optimized the magento except the inabibility to optimize the template code which I purchased from joomlart.

Another thing I tried is to install the varnish extention, but I just failed to make it work after numerous trys.

Social Links in Virtuemart Powered shops

I built a joomla + virtuemart powered online shopping cart years ago and since then, paid little attention to the implementation of social networking until months ago I recognized the importance of such socoial media as facebook, twitter and linkedin.

So, how? I checked the related extensions on joomla and tested. And for the homepage, I just installed a module and published it, it works! But for the virtuemart prodcut details and catalog page, just no quick fix.

And I have to install the plugin first and then copy the plugin code as required into the product description manually, and fortunately,  I have only abt. 100 products and is relatively easy to implement that. For a site with much more products, it would be formidable job.

Adding such social extentions to the site would also have an effect on the performance, so far I failed to get a more clear idea of how to boost a joomla powered site except the CDN, CACHE, MINIFY & COMPRESSION OF THE CSS AND JS FILES.

The cache issue does pose to be a challenging job, whenever I enable the browser cache in the joomla cache plugin, always there is be a problem with the user login modue, no solution yet.

The social module and plugin extentions I used are from and can be found below.

http://extensions.joomla.org/extensions/social-web/republish/15665

Implementing Xcache on Bluehost

Days ago, I read an article about boosting the performance of BLUEHOST shared hosting, which said that by implementing Xcache, the performance would be improved.

So I gave it a try and installed Xcache on my Bluehost account, just as what I did with my LINODE VPS hosting, and yes, the Xcache began to work after the installation, and to some extent, I felt that my JOOMLA site performed a little better.

However, after checking the admin page of Xcache page, I just found that the cache would be cleared every about 10 minutes, which means you gain nothing when it comes to the performance improvement if your cache keeps being cleared in such a short time interval.

And the thing that cache beding cleared puzzled me a lot, so I googled and just found that the culprit was indeed the fastcgi process, BLUEHOST sets  fastcig process with a 10 minutes limite and kills the process after that time limit.

Unlike my VPS hosting with Linode, the fastcig just persists as long as you don’t restart the process.

And someone proposed that by setting up a cron job to excute the website’s index.php every 5 mintues to keep at least one fastcgi process alive, which seems to be a good idea, I did that but still found no much improvement.

I don’t know much about the ways to improve shared hosting like Bluehost, and even after seaching google,  I just can’t find good practive for that.

Details about the XCACHE implementation can be found in the article below.

http://rk.md/2009/xcache-bluehost/