Search

Mar 17, 2023

Setup multiple sites with nginx config on Magento 2

1. Create /etc/nginx/sites-available/spi24.conf

server
{
	listen 80;

	server_name spi24.local;

	set $MAGE_ROOT /var/www/html/spi24;
	set $MAGE_DEBUG_SHOW_ARGS 0;
	set $MAGE_RUN_TYPE website;
	set $MAGE_RUN_CODE base;
	include /var/www/html/spi24/nginx.conf;

	# Logs (access et errors)
	access_log /var/www/html/spi24/var/log/nginx-access.log;
	error_log /var/www/html/spi24/var/log/nginx-error.log;


}

server
{
	listen 80;

	server_name hts24.local;

	set $MAGE_ROOT /var/www/html/spi24;
	set $MAGE_DEBUG_SHOW_ARGS 0;
	set $MAGE_RUN_TYPE website;
	set $MAGE_RUN_CODE hts;
	include /var/www/html/spi24/nginx.conf;

	# Logs (access et errors)
	access_log /var/www/html/spi24/var/log/nginx-access.log;
	error_log /var/www/html/spi24/var/log/nginx-error.log; 
} 


2. Create /etc/nginx/sites-available/magento.conf

upstream fastcgi_backend {

# M2.1
# server unix:/var/run/php/php7.0-fpm.sock;

# M2.3 
#       server   unix:/var/run/php/php7.2-fpm.sock; 

#       server   unix:/var/run/php/php7.3-fpm.sock;

# M2.4.3 
        server   unix:/var/run/php/php7.4-fpm.sock;

# M2.4.4 
#       server   unix:/var/run/php/php8.1-fpm.sock;
}


3. Create symlink

sudo ln -s /etc/nginx/sites-available/spi24.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/magento.conf /etc/nginx/sites-enabled/


4. Check nginx.conf file

on /var/www/html/spi24/nginx.conf

# PHP entry point for main application
# default
#location ~ ^/(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {

# multi store
location ~ /(index|get|static|errors/report|errors/404|errors/503|health_check)\.php$ {


5. Check services


sudo service php*.*-fpm start  // Check step 2
sudo nginx -t
sudo service nginx restart


Magento 2 The website with id that was requested wasn't found. Verify the website and try again

The website with id 6 that was requested wasn't found. Verify the website and try again.

First Solution:

1. Go to app/etc/config.php file
2. Remove all store, website id = 6
3. bin/magento set:up
4. Clear cache


The website with id 6 that was requested wasn't found. Verify the website and try again. Exception in /vendor/magento/module-store/Model/WebsiteRepository.php:110

 ## report.CRITICAL: The website with id 6 that was requested wasn't found. Verify the website and try again. {"exception":"[object] (Magento\\Framework\\Exception\\NoSuchEntityException(code: 0): The website with id 6 that was requested wasn't found. Verify the website and try again. at /vendor/magento/module-store/Model/WebsiteRepository.php:110)"}

Second Solution:

1. Find all rows on magento_versionscms_hierarchy_node table where scope_id = 6
2. I deleted 2 rows on the table magento_versionscms_hierarchy_node where scope_id = 6