[TomatoCart] Nginx Web Server Support

Until this day, Apache remains the most popular web server. Most likely, it is being used to run your very own TomatoCart store. But, there is another powerful web server called nginx as an alternative to apache. It is very fast and ideal for high traffic websites. It is not difficult to run your TomatoCart store within nginx, you just need to complete following steps.

Note: I am using Ubuntu as the VPS operation system. The steps in this tutorial require the user to have root privileges.

Step 1. Install nginx

sudo apt-get update
sudo apt-get install nginx

Now that you installed the nginx, you could start, stop and restart it.

sudo service nginx start
sudo service nginx stop
sudo service nginx restart

You can confirm that nginx working correctly by directing your browser to your IP address. Run the following command to find your server’s IP address.

ifconfig eth0 | grep inet | awk '{ print $2 }'

If it works, you will see a following screenshot.


Step 2. Install PHP-FPM

For working with nginx, we have to install PHP5-FPM.

sudo apt-get install php5-fpm

Step 3. Configure php


sudo vim /etc/php5/fpm/php.ini

Find cgi.fix_pathinfo=1, and change the 1 to 0.


 sudo vim /etc/php5/fpm/pool.d/www.conf

Find listen = to change it to /var/run/php5-fpm.sock.


Restart it now to load new configurations

sudo service php5-fpm restart

Step 4. Setup virtual hosts

Copy the default host file to a new host file matched with your store domain. For example, i am using tomatocart.com for my store. So i name it tomatocart.com.

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/tomatocart.com

Open up tomatocart.com.

sudo vim /etc/nginx/sites-available/tomatocart.com

Clean the content and enter following content into it.

server {
    listen 80;
    server_name  tomatocart.com www.tomatocart.me;

    root /var/www/tomatocart;
    index index.php index.html;

    location /admin {
        index index.php;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;

    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        log_not_found off;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
  • Update the server_name directive with your own server name.
  • Update the root directive with your own root directory of your store in the server.

Link the /etc/nginx/sites-available/tomatocart.com with /etc/nginx/sites-enabled/tomatocart.com.

sudo ln -s /etc/nginx/sites-available/tomatocart.com /etc/nginx/sites-available/tomatocart.com

Restart the nginx to load the virtual host configurations.

sudo service nginx restart

Now, you could access your store served by nginx. If your store is a new store, you have to install php5 and mysql too. Please read the installation guide of TomatoCart.

Looking for quality TomatoCart hosting? Check out Arvixe Web Hosting

Tags: | Posted under TomatoCart | RSS 2.0

Author Spotlight

Jack Yin

TomatoCart Developer & Co Founder - Arvixe Web Hosting / TomatoCart Community Liaison

Leave a Reply

Your email address will not be published. Required fields are marked *