I was trying to setup multi stores and store views with different domains on NGINX.
Here is the structure of my website (sorry, I really don't know how to use the list):
- Main Website (only one)
- clothes (store)
- clothes_vi (store view, desired domain: vi.clothes.local)
- clothes_en (store view, desired domain: e.clothes.local)
- computer (store)
- computer_vi (store view, desired domain: vi.computer.local)
- computer_en (store view, desired domain: en.computer.local)
To achieve the desired domain above for each store view, I configured:
/etc/nginx/sites-available:
upstream fastcgi_backend {
server unix:/run/php/php7.1-fpm.sock;
}
map $http_host $MAGE_RUN_CODE {
en.computer.local computer_en;
vi.computer.local computer_vi;
en.clothes.local clothes_en;
vi.clothes.local clothes_vi;
}
server {
listen 80;
server_name en.computer.local vi.computer.local en.clothes.local vi.clothes.local;
set $MAGE_ROOT <project_dir>;
include <project_dir>/nginx.conf;
}
project_dir/nginx.conf:
Add:
fastcgi_param MAGE_RUN_TYPE store;
fastcgi_param MAGE_RUN_CODE $MAGE_RUN_CODE;
Below:
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
And set the above domain for each of the store view in store configuration.
With above configuration, when I go to the front-end and access each of the store view using the drop down list appeared there, with my configured domains. However, if I type in the url myself before using the drop down list, it'll redirect me to the url of default store view, which is vi.clothes.local.
Detailed cases:
Stay at vi.clothes.local, go to computer_en using the drop down list in front-end -> redirect to en.computer.local and the corresponding store.
Do case 1, then type en.computer.local on address bar -> the same correct result
Type en.computer.local on address bar without doing case 1, or use incognito mod -> redirect to vi.clothes.local and the default store.
Why this is happening and how to achieve my goal? Any help is appreciated please!