ECommerce Insights Blog

Stay on top of it all and get ahead with useful articles, how-tos, tips and tricks on e-commerce.

Configuring Nginx To Use Single Magento Instance For Running Multiple Stores

nginx_to_magento
One of our customers requested us whether we can help him configure his server (running Nginx) and make it run multiple Magento stores on single Magento instance. In the past we have written a comprehensive guide on How to configure Magento to run on lightweight Nginx server, that helped many people figuring out the basics. This new problem took us little time to figure out the real solution. Answer to the question “how we can build a multi-store Magento that uses single Magento instance on Nginx” was found in Nginx module map that is something we should consider. If you are also looking to run multi-store environment on single Magento instance this solution will save you hours.

Most probably you must have configured your store like this

/ Etc / nginx / sites-Enables / example.com

Simply edit the configuration file to define map block the way it’s listed below

map {$ HTTP_HOST $ mage_run_code
    example.com USA;
    example.com.it Italy;
    example.com.fr France;
}

We are going to assign codes from admin backend that will match with the website codes for each domains. Then, we should create another server block to define the domains.

server {
    listen 80;
    server_name example.com.it;
 
    ...
 
}

and

server {
    listen 80;
    server_name example.com.fr;
 
    ...
 
}

We prefer php-fpm so under php-fpm settings you will have a block like the following

location ~ \. php $ {
    fastcgi_pass unix :/ var/run/php5-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
 
    ...
 
}

Now, add the following 2 lines

fastcgi_param MAGE_RUN_TYPE website;
fastcgi_param MAGE_RUN_CODE $ mage_run_code;

Finally, restart the Nginx webserver and test the other web stores running the single Magento instance.

I hope this will help you run single Magento instance that can power multiple store views. Moreover, in terms of management this is a much simpler and easier. Please leave us a comment and let us know how you have created a multi-store Magento on single Magento instance?