apt-get -y install Nginx
apt-get -y install php7.0-fpm php7.0-cli
vim /etc/php/7.0/fpm/php.ini
vim /etc/php/7.0/cli/php.ini
memory_limit = 2G;
max_execution_time = 1800
zlib.output_compression = on
systemctl restart php7.0-fpm
service restart nginx
systemctl -h nginx
/etc/nginx/sites-available.
/var/www/html/magento2
/etc/nginx/sites-available/magento:
map $http_host $MAGE_RUN_CODE {
default ”;
canada.site.com canada;
mexico.site.com mexico;
}
server {
listen 80;
server_name site.com canada.site.com mexico.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;
}
nginx: configuration file /etc/nginx/nginx.conf test is successful If errors display, check the syntax of your virtual host configuration files.
/etc/nginx/sites-available/canada.site.com:
map $http_host $MAGE_RUN_CODE {
canada.site.com canada;
}
server {
listen 80;
server_name canada.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;
}
Create another file named mexico.site.com in the same directory with the following contents:
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;
}
nginx: configuration file /etc/nginx/nginx.conf test is successful If errors display, check the syntax of your virtual host configuration files.
$bootstrap =\Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
With this,
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘canada’;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘website’;
$bootstrap
=\Magento\Framework\App\Bootstrap::create(BP, $params);
$bootstrap
=\Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
With this,
$params = $_SERVER;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE] = ‘mexico’;
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_TYPE] = ‘website’;
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $params);
sudo vim /etc/nginx/conf.d/site.com.conf
server{
listen 80;
server_name site.com;
set $MAGE_ROOT /var/www/html/magento2;
set $MAGE_MODE developer;
include /var/www/html/magento2/nginx.conf;
}
And if you have multiple websites in it, then add this in file as follows
location /canada/ {
set
$MAGE_ROOT /var/www/vhosts/site.com/httpdocs/pub;
set $MAGE_MODE developer;
try_files $uri $uri/ /canada/index.php?$args;
}
location /mexico/ {
set
$MAGE_ROOT /var/www/vhosts/site.com/httpdocs/pub;
set $MAGE_MODE developer;
try_files $uri $uri/ /mexico/index.php?$args;
}
sudo vim /etc/nginx/conf.d/canada.site.com.conf and sudo vim /etc/nginx/conf.d/mexico.site.com.conf
Canada
server{
listen 80;
server_name canada.site.com;
set $MAGE_ROOT /var/www/html/magento2/canada/;
set $MAGE_MODE developer;
include /var/www/html/magento2/nginx.conf;
}
Mexico
server{
listen 80;
server_name mexico.site.com;
set $MAGE_ROOT /var/www/html/magento2/mexico/;
set $MAGE_MODE developer;
include /var/www/html/magento2/nginx.conf;
}
Conclusion
We hope you have understood the configuration for the Nginx in Magento 2. Both Apache and Nginx have many different qualities. While Apache configuration is easier than Nginx, the latter is way better than Apache in terms of performance and lightweight results.
If you’re a Magento Developer or a Magento Development Agency, then you know that it is not entirely easy to perform this process. Moreover, it is not a cup of everyone’s tea to digest all the information we have provided and integrate it easily with proper settings.
Hence, it is wiser to partner with an agency providing Magento Development Services. It will save you considerable time and human resources. And you will get your work carried out by Magento experts.
At ZealousWeb, we have a team of Magento professionals experienced in Nginx integration in Magento 2 for multiple websites. You can bank on our expertise and enjoy premier-quality output.
Moreover, if you have any questions or want a quotation for our services, feel free to contact us at hello@zealousweb.com.