This question already has an answer here:

So I have been struggling with this multiple times now and every time just procrastinated it because it wasn't a priority.

We are running a Magento 2.2.2 store using php 7.1.22 and Nginx 1.14.0.

We recently switched from a single website with 2 stores to 2 websites with both one store. This so we can configure our parcel plugin for different shipping rates. (This is a requirement from the plugin).

Both of these websites have different domain names, and I want the domains to end up at their respective websites and store views. The problem no matter what I do the default store get's displayed.

The current magento store configuration:

| Website id      | Store id           | Storeview id |
| base            | main_website_store | default      |
| xatdistribution | XAT                | XAT_NL       |

The Nginx configuration:

├── sites-available
│   ├── magento-domotica
│   └── magento-xat
└── sites-enabled
    ├── magento-domotica -> /etc/nginx/sites-available/magento-domotica
    └── magento-xat -> /etc/nginx/sites-available/magento-xat

The file sites-available/magento-domotica:

upstream fastcgi_backend {
    server   unix:/var/run/php/php7.1-fpm.sock;

server {
    listen 80;
    server_name domotica-shop.nl www.domotica-shop.nl;
    return 301 https://$host$request_uri;

server {
    server_name domotica-shop.nl www.domotica-shop.nl;

    proxy_cookie_path / "/; HTTPOnly; Secure";
    add_header Access-Control-Allow-Origin www.domotica-shop.nl;
    set $MAGE_ROOT /var/www/magento/html;
    set $MAGE_MODE developer;
    set $MAGE_RUN_TYPE website;
    set $MAGE_RUN_CODE base;
    include /var/www/magento/html/nginx.conf.sample;
    fastcgi_read_timeout 3000;

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/***/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/***/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

The file sites-available/magento-xat is almost the same as sites-available/magento-domotica, only the domain name and $MAGE_RUN_CODE are different. (The upstream is also removed there)

I did add the 2 lines in main application location block inside the nginx.conf.sample in the Magento webroot.

# 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=756M \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;
    fastcgi_param MAGE_RUN_TYPE $MAGE_RUN_TYPE;
    fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
    include        fastcgi_params;

I followed the guide in the magento documentation, with no luck.

I am stuck here. The default store view (wich is also default) keeps getting shown, also on the other domain.

marked as duplicate by Jai, Muhammad Hasham, Aasim Goriya, saravanavelu, Mohit Kumar Arora May 8 at 4:59

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • to help you debug this issue you can add $MAGE_RUN_TYPE $MAGE_RUN_CODE into http headers and check which one you see. – MagenX May 8 at 8:49