With nearly 30 percent market share, Magento is the most popular e-commerce platform in the world. Due to a number of features and complexity, it’s also a very resource-intensive system to use compared to a lightweight alternative. This means that NGINX is an ideal pairing to ensure you have the highest performance possible.
The latest major version of Magento is 2.3, which was nearly a complete rewrite compared to the previous versions. There’s still quite a bit of complexity involved too, so make sure that you’re ready to take on Magento if you’ve chosen it for your e-commerce platform.
Magento provides a fairly functional NGINX sample configuration (located in the root of the Magento source folder) to get started with. I’ve located the files within the /var/www/html directory, which will be known as MAGE_ROOT.
I’ve created a dedicated config file just for the Magento site (/etc/nginx/conf.d/magento2.conf)
nano /etc/nginx/conf.d/magento2.conf
Then copy and paste the content below into the file and save.
upstream fastcgi_backend {
server unix:/var/run/php/php7.3-fpm.sock;
}
server {
listen 80;
server_name magento.local;
set $MAGE_ROOT /var/www/html;
include /var/www/html/nginx.conf.sample;
}
Reload NGINX to read the new configuration file.
sudo service nginx reload