Multi-Website Setup On Magento2 By Nginx
Sanjay Kumar Das
2 min read
go the the directory = cd /etc/nginx/sites-available
create a file i.e = sudo nano local (paste the below data - here i am doing two site setup)
#------------------------------------------------------------------->
upstream fastcgi_backend {
server unix:/run/php/php8.1-fpm.sock;
}
map $http_host $MAGE_RUN_CODE {
default '';
dev.forevernew.co.nz fn_nz;
dev.forevernew.co.au fn_au;
}
server {
listen 80;
server_name dev.local.co.nz dev.local.co.nz dev.local.co.au;
set $MAGE_ROOT /var/www/html/local;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE website; #or set $MAGE_RUN_TYPE store;
include /var/www/html/local/nginx.conf.sample;
}
#------------------------------------------------------------------->
get the website code from this magento table i.e = store_website (get the Code column value )[here fn_nz and fn_au are website code ]
Step -2
create two more file inside this {" cd /etc/nginx/sites-available " directory} [two store so - two file create if more create more file]
i) sudo nano dev.local.co.nz (paste the below data)
server {
listen 80;
server_name dev.local.co.nz;
set $MAGE_ROOT /var/www/html/local;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE website; #or set $MAGE_RUN_TYPE store;
set $MAGE_RUN_CODE fn_nz;
include /var/www/html/local/nginx.conf.sample;
}
ii) sudo nano dev.forevernew.co.au (paste the below data)
server {
listen 80;
server_name dev.local.co.au;
set $MAGE_ROOT /var/www/html/local;
set $MAGE_MODE developer;
set $MAGE_RUN_TYPE website; #or set $MAGE_RUN_TYPE store;
set $MAGE_RUN_CODE fn_au;
include /var/www/html/local/nginx.conf.sample;
}
Step -3
- create the all 3- files symlink to cd /etc/nginx/sites-enabled
- sudo ln -s /etc/nginx/sites-available/local /etc/nginx/sites-enabled
- sudo ln -s /etc/nginx/sites-available/dev.local.co.nz /etc/nginx/sites-enabled
- sudo ln -s /etc/nginx/sites-available/dev.local.co.au /etc/nginx/sites-enabled
- sudo nginx -t
- sudo service nginx restart
Step -4
- Go the your magento folder location (e.g = /var/www/html/local )
- Find nginx.conf.sample file
- Edit ---> nginx.conf.sample
- Search below location
Previous (existing)
=====================
# PHP entry point for main application
location ~ (index|get|static|report|404|503|health_check)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=1G \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Step -5
- Modify the above with Below Two Line (Before " include fastcgi_params; Line)
#------------------------------------------------------------------->
- fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
- fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
#------------------------------------------------------------------->
Step -6
After Modify (currently)
========================
# PHP entry point for main application
location ~ (index|get|static|report|404|503|health_check)\.php$ {
try_files $uri =404;
fastcgi_pass fastcgi_backend;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=1G \n max_execution_time=18000";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#------------------------------------------------------------------->
# START - Multisite customization
fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
# END - Multisite customization
#-------------------------------------------------------------------->
include fastcgi_params;
}
0
Subscribe to my newsletter
Read articles from Sanjay Kumar Das directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sanjay Kumar Das
Sanjay Kumar Das
Full-Stack Developer