cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple website on multi domain with nginx not working

Multiple website on multi domain with nginx not working

I have two websites and two domains in one installation, but the domain redirect seems not work.

map $http_host $MAGE_RUN_CODE {

    a.com base1;

    www.a.com base1;

    b.com base2;

    www.b.com base2;

}

map $http_host $MAGE_RUN_TYPE {

    a.com website;

    www.a.com website;

    b.com website;

    www.b.com website;

}

 

nginx.conf

fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;

fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;

 

 

b.com always redirect to a.com

I think my settings is right, I don't where is mistake.

6 REPLIES 6

Re: Multiple website on multi domain with nginx not working

www.b.com works well, but if I typed b.com, it will redirect to a.com

I also configured base url for each website in dashboard.

Re: Multiple website on multi domain with nginx not working

Hello @Magentobiz_com 

 

map $http_host $MAGE_RUN_CODE {
    default '';
    french.mysite.mg french;
    german.mysite.mg german;
}

server {
    listen 80;
    server_name mysite.mg french.mysite.mg german.mysite.mg;
    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;
}
map $http_host $MAGE_RUN_CODE {
    french.mysite.mg french;
}

server {
    listen 80;
    server_name french.mysite.mg;
    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;
}
map $http_host $MAGE_RUN_CODE {
    german.mysite.mg german;
}

server {
    listen 80;
    server_name german.mysite.mg;
    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;
}

More info check

https://devdocs.magento.com/guides/v2.3/config-guide/multi-site/ms_nginx.html

 

If works then mark as solution

 


Problem solved? Click Kudos & Accept as Solution!
Sunil Patel
Magento 2 Certified Professional Developer & Frontend Developer

Re: Multiple website on multi domain with nginx not working

Do I have to create three nginx conf files?

Re: Multiple website on multi domain with nginx not working

I modified file refer to your configuration. but it totally not working, and now whatever b.com or www.b.com both will redirect to a.com.

Re: Multiple website on multi domain with nginx not working

I have no ideaSmiley SadSmiley SadSmiley Sad

upstream fastcgi_backend {

     server  unix:/var/run/php-fpm/www.sock;

}

map $http_host $MAGE_RUN_CODE {

    default '';

    a.com base;

    www.a.com base;

    b.com base1;

    www.b.com base1;

}

 

server {

     listen 80;

     server_name a.com www.a.com b.com www.b.com;

     set $MAGE_ROOT /website/magento;

     set $MAGE_MODE developer;

     set $MAGE_RUN_TYPE website;

     include /website/magento/nginx.conf;

}

 

/website/magento/nginx.conf:

..........................

fastcgi_param  PHP_VALUE "memory_limit=756M \n max_execution_time=18000";

    fastcgi_read_timeout 600;

    fastcgi_connect_timeout 600;

 

    fastcgi_param  MAGE_RUN_TYPE $MAGE_RUN_TYPE;

    fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;

 

    fastcgi_index  index.php;

..........................

Re: Multiple website on multi domain with nginx not working

Please change your $MAGE_RUN_CODE to another name. Ex:  $MAGE_RUN_CODE_AB
And update it in nginx.conf also.
The problem is you are using $MAGE_RUN_CODE in another server configuration.