How to run multiple Magento store views

Serve several Magento store views or websites from one installation on different domains, using MAGE_RUN_CODE and MAGE_RUN_TYPE in the TurboStack Nginx config.

One Magento installation can serve several store views or websites, each on its own domain. Magento selects which one to load from two variables, MAGE_RUN_CODE (the store-view or website code) and MAGE_RUN_TYPE (store or website). On TurboStack you set them per domain in your Nginx configuration.

Before you start

  • Your store views or websites already created in Magento (Stores > All Stores), each with its code.
  • Secure Shell (SSH) access to the host - see SSH access. You edit files under your system user's ~/nginx/ directory.

Map each domain to a store code

Create ~/nginx/mage.runmaps and map each host name to its code and type. MAGE_RUN_TYPE is either store (a store view) or website:

map $http_host $MAGE_RUN_CODE {
    hostnames;
    .domain.nl  domainnl;
    .domain.fr  domainfr;
}

map $http_host $MAGE_RUN_TYPE {
    hostnames;
    .domain.nl  store;
    .domain.fr  store;
    default     website;
}

Replace domainnl and domainfr with your store-view or website codes from Stores > All Stores.

Pass the variables to Magento

In ~/nginx/50main.conf, find the two commented fastcgi_param lines in the PHP location block and remove the leading # so they are active:

fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE if_not_empty;
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE if_not_empty;

Publish the host (or reload Nginx with tscli nginx reload) to apply the change, then load each domain and confirm it shows the right store view.

Verify

List the configured base URLs per store to confirm each code resolves to the right domain:

magerun2 sys:store:config:base-url:list