1

I am trying to setup a multistore or multiwebsite in magento 2. My server is using nginx. Can any one please tell me the steps to work on it.

What i have tried so far.

1) By following magento2 doc i made changes in nginx.magento.conf and main.conf which is located at /etc/nginx/conf.d/

2) Made host entry in /etc/hosts

3) Made host entry on my windows C:\Windows\System32\drivers\etc\hosts

But i am not able to get my second website in running state.

Here are the files .

1) main.conf

upstream fastcgi_backend {
    server  127.0.0.1:9000;
}

server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/local/local.pem;
    ssl_certificate_key /etc/ssl/certs/local/local.key;
    server_name magento2-dev.local magento2-demo.local;
    set $MAGE_ROOT /var/www/magento2-dev.local;
    set $MAGE_MODE developer;
    include /etc/nginx/conf.d/nginx.conf.magento2;
}

map $http_host $MAGE_RUN_CODE {
    magento2-dev.local base;
    magento2-demo.local site2;
}

Another tried Way

    upstream fastcgi_backend {
    server  127.0.0.1:9000;
}

server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/local/local.pem;
    ssl_certificate_key /etc/ssl/certs/local/local.key;
    server_name magento2-dev.local;
    set $MAGE_ROOT /var/www/magento2-dev.local;
    set $MAGE_MODE developer;
    include /etc/nginx/conf.d/nginx.conf.magento2;
}


server {
    listen 80;
    listen 443 ssl;
    ssl_certificate /etc/ssl/certs/local/local.pem;
    ssl_certificate_key /etc/ssl/certs/local/local.key;
    server_name magento2-demo.local;
    set $MAGE_ROOT /var/www/magento2-dev.local;
    set $MAGE_MODE developer;
    include /etc/nginx/conf.d/nginx.conf.magento2;
}


map $http_host $MAGE_RUN_CODE {
    magento2-dev.local base;
    magento2-demo.local site2;
}

2) nginx.magento.conf

# Magento Vars
# set $MAGE_ROOT /path/to/magento/root;
# set $MAGE_MODE default; # or production or developer
#
# Example configuration:
# upstream fastcgi_backend {
#    # use tcp connection
#    # server  127.0.0.1:9000;
#    # or socket
#    server   unix:/var/run/php5-fpm.sock;
# }
# server {
#    listen 80;
#    server_name mage.dev;
#    set $MAGE_ROOT /var/www/magento2;
#    set $MAGE_MODE developer;
#    include /vagrant/magento2/nginx.conf.sample;
# }


root $MAGE_ROOT/pub;

index index.php;
autoindex off;
charset off;

add_header 'X-Content-Type-Options' 'nosniff';
add_header 'X-XSS-Protection' '1; mode=block';

location /setup {
    root $MAGE_ROOT;
    location ~ ^/setup/index.php {
        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    location ~ ^/setup/(?!pub/). {
        deny all;
    }

    location ~ ^/setup/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}

location /update {
    root $MAGE_ROOT;

    location ~ ^/update/index.php {
        fastcgi_split_path_info ^(/update/index.php)(/.+)$;
        fastcgi_pass   fastcgi_backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        include        fastcgi_params;
    }

    # deny everything but index.php
    location ~ ^/update/(?!pub/). {
        deny all;
    }

    location ~ ^/update/pub/ {
        add_header X-Frame-Options "SAMEORIGIN";
    }
}

location / {
    try_files $uri $uri/ /index.php?$args;
}

location /pub {
    location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\                                                                                                                                                             .xml) {
        deny all;
    }
    alias $MAGE_ROOT/pub;
    add_header X-Frame-Options "SAMEORIGIN";
}

location /static/ {
    if ($MAGE_MODE = "production") {
        expires max;
    }
    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$                                                                                                                                                              {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;

        if (!-f $request_filename) {
            rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;

        if (!-f $request_filename) {
           rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
        }
    }
    if (!-f $request_filename) {
        rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

location /media/ {
    try_files $uri $uri/ /get.php?$args;

    location ~ ^/media/theme_customization/.*\.xml {
        deny all;
    }

    location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$                                                                                                                                                              {
        add_header Cache-Control "public";
        add_header X-Frame-Options "SAMEORIGIN";
        expires +1y;
        try_files $uri $uri/ /get.php?$args;
    }
    location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
        add_header Cache-Control "no-store";
        add_header X-Frame-Options "SAMEORIGIN";
        expires    off;
        try_files $uri $uri/ /get.php?$args;
    }
    add_header X-Frame-Options "SAMEORIGIN";
}

location /media/customer/ {
    deny all;
}

location /media/downloadable/ {
    deny all;
}

location /media/import/ {
    deny all;
}

location ~ cron\.php {
    deny all;
}

location ~ (index|get|static|report|404|503)\.php$ {
    try_files $uri =404;
    fastcgi_pass   fastcgi_backend;

    fastcgi_param  PHP_FLAG  "session.auto_start=off \n suhosin.session.cryptua=                                                                                                                                                             off";
    fastcgi_param  PHP_VALUE "memory_limit=256M \n max_execution_time=600";
    fastcgi_read_timeout 600s;
    fastcgi_connect_timeout 600s;
    fastcgi_param  MAGE_MODE $MAGE_MODE;
    fastcgi_param  MAGE_RUN_TYPE website;
    fastcgi_param  MAGE_RUN_CODE $MAGE_RUN_CODE;

    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

3) server hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 magento2-demo.local magento2-dev.local
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

4) My Windows hosts file

192.168.56.104 magento2-dev.local
192.168.56.104 magento2-demo.local

My present result is for http://magento2-dev.local/

enter image description here

and for http://magento2-demo.local/

enter image description here

Can any one please help me to find my mistakes.

2

It doesn't look like you're listening on magento2-demo.local.

The line server_name magento2-dev.local; should contain all appropriate aliases, so in this case server_name magento2-dev.local magento2-demo.local; inside your main.conf server entry.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.