How to run multiple Magento store views
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.
Note
If the host already has store-code mappings for another system user, keep them separate by appending your user name to the variables: use $MAGE_RUN_CODE_<username> and $MAGE_RUN_TYPE_<username> in both mage.runmaps and 50main.conf.
Verify
List the configured base URLs per store to confirm each code resolves to the right domain:
magerun2 sys:store:config:base-url:list
Note
magerun2 (n98-magerun2) is a third-party command-line tool, not part of core Magento.