Ecommerce Magento 2 Magento 2 Tutorials

How to Set Up Multiple Websites with Nginx Configuration in Magento 2?

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.50 out of 5)
Loading...Loading...
Nginx Configuration in Magento 2

Today, we’re going to teach you guys how to set up multiple websites with Nginx configuration in Magento 2.

Nginx is basically an open-source web server that is often used for highly scalable architectures & provides high performance.

It combines the best features of reverse proxy, mail proxy, HTTP load balancer, and content cache. 

In simple words, it is an event-driven approach that processes multiple requests at the same time using PHP-fpm.

And now, you can easily set up multiple websites with Nginx configuration in your Magento 2 store.

Step-By-Step Process to Set Up Multiple Websites with Nginx Configuration in Magento 2

Please follow the below steps to learn how to set up multiple websites with Nginx configuration in your Magento 2 store.

Step – 1

First of all, you need to create a new website.

For this, log in to your admin panel and navigate to Stores > Setting > All Stores.

Now, click on the Create Website button and do the following:

  • Write a name for your new website in the Name field.
  • Write a unique code for your new website in the Code field.
  • Enter a numeric sort order for your new website in the Sort Order field.
  • Click on the Save Config button to finish the process of creating a new website.

Step – 2

After that, we need to create & configure the Nginx virtual hosts.

For this, we need to create one virtual host for the newly created website. 

So, open any text editor and copy the following code into the file:

map $http_host $MAGE_RUN_CODE {

default ”;

canada.site.com canada;

mexico.site.com mexico;

}

server {

listen 80;

server_name site.com canada.site.commexico.site.com;

set $MAGE_ROOT /var/www/html/magento2;

set $MAGE_MODE developer;

set $MAGE_RUN_TYPE website; or store

include /var/www/html/magento2/nginx.conf;

}

  • Now, save the file with magento: name in the /etc/nginx/sites-available/ folder.
  • Verify the server configuration: nginx -t
  • If the server configuration was successful, then you’ll see a message as below:

nginx: configuration file /etc/nginx/nginx.conf test is successful

Step – 3

Next, we need to create mexico.site.com file in the same folder as above and paste the following code:

    map $http_host $MAGE_RUN_CODE {

    mexcio.site.com mexico;

    }

    server {

    listen 80;

    server_name mexico.site.com;

    set $MAGE_ROOT /var/www/html/magento2;

    set $MAGE_MODE developer;

    set $MAGE_RUN_TYPE website; #or set $MAGE_RUN_TYPE store;

    include /var/www/html/magento2/nginx.conf;

    }

  • Verify the server configuration: nginx -t
  • If the server configuration was successful, then you’ll see a message as below:

nginx: configuration file /etc/nginx/nginx.conf test is successful

Step – 4

Now, simply restart the Nginx service by executing the following command to verify if it’s working properly or not.

service nginx restart

Final Note

And that’s about it!

This is how you can set up multiple websites with Nginx configuration in Magento 2.

We hope that you found this tutorial helpful. If you have any doubts, please ask them in the comments below.

And if you need our professional assistance, feel free to contact us anytime.

You may also like
Magento 2 Vs Opencart
Magento 2 Vs OpenCart: The Major Differences
Top Rated Customer Attribute Module for Magento 2 Stores
Top Rated Customer Attribute Module for Magento 2 Stores

Leave Your Comment

Your Comment*

Your Name*