Setting Up Multistore Magento with Nginx
Magento is a robust e-commerce platform that allows you to manage multiple stores from a single installation. While the core documentation covers basic setup, it often misses crucial details for advanced configurations like multistore using multiurl with Nginx. In this guide, we’ll walk through the process step-by-step.
Prerequisites
Before getting started, ensure you have:
- A Magento installation (2.x or 3.x)
- An Nginx web server setup
- Access to your server’s configuration files
- Familiarity with basic Apache-to-Nginx migration concepts
Setting Up Multistore in Magento
First, let’s create the multistore configuration within your Magento admin panel:
- Login to your Magento backend.
- Navigate to Stores > All Stores.
- Click ‘Create Store’ button.
- Fill in the store name and website details, then click ‘Create’.
- Repeat for additional stores.
Configuring Nginx for Multistore
Now, we need to configure Nginx to recognize these multiple stores. Here are key steps:
1. Enable Magento’s multiurl mode
In your Magento root folder, navigate to app/etc/modules/Magento_UrlRewrite.xml and ensure the following is set:
<active_from_state>active</active_from_state>
This enables Magento’s built-in URL rewrite functionality required for multistore.
2. Update Nginx Configuration
Open your primary Nginx configuration file (usually nginx.conf).
Find or create a new server block for each additional domain as needed:
server {
listen 80;
listen [::]:80;
server_name store2.com www.store2.com;
return 301 $scheme://www.$host$request_uri;
location / {
rewrite ^(.*)$ /index.php?$1 last;
}
}
Replace store2.com with the domain of your second store.
3. Configure Additional Domains
For each additional domain, create a new config file (e.g., store2.conf) with:
server {
listen 80;
listen [::]:80;
root /var/www/html/magento-store2/public;
index index.php;
server_name store2.com www.store2.com;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
Note that /var/www/html/magento-store2/public should point to your actual Magento install for the second store.
Conclusion
Setting up multistore with Nginx requires careful attention to both Magento’s configuration and your server setup. By following this guide, you can effectively manage multiple stores from a single installation while leveraging the performance benefits of Nginx.
Remember that proper security measures should be in place, including using SSL certificates for each domain and restricting file permissions on your server as needed.
For more advanced configurations and best practices, check out our detailed guides at Laravel Company.