# Nginx Magento multistore configuration

**URL:** <https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664>\
**Category:** NGINX\
**Created:** [July 14, 2015, 12:04am UTC](https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664 "2015-07-14T00:04:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [July 14, 2015, 12:04am UTC](https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664/1 "2015-07-14T00:04:37Z")

</div>

There is a website that has multiple subcatogories which are stores in  
magento:

[www.website.com/sub1](http://www.website.com/sub1) [www.website.com/sub2](http://www.website.com/sub2) [www.website.com/sub3](http://www.website.com/sub3)

The server used is ngnix. everything is set up. And used to work, the  
nginx  
conf file for this site need to be reconstructed.

at the moment when for example [www.website.com/sub1](http://www.website.com/sub1) is requested this  
wil  
set the store to store to sub1. which works fine. However when a product  
is  
asked i.e. [www.website.com/sub1/product](http://www.website.com/sub1/product) this returned a “page not found”  
error.

If the store is set to sub1 the url [www.website.com/product](http://www.website.com/product) DOES FIND  
the  
product without any issues. on the other hand f the store was not set  
previously, [www.website.com/product](http://www.website.com/product) DID NOT FIND the product.

it seemed that once a store is set the following happens e.g.  
[www.website.com/sub1/product](http://www.website.com/sub1/product) :

sub1-\>sub1-\>product == error (because of sub1-\>sub1)

this should be:

sub1-\>product.

note that setting the store when [www.website.com/sub1/product](http://www.website.com/sub1/product) is  
requested  
and then redirecting the site to [www.website.com/product](http://www.website.com/product) is not an  
option.  
everything used to work fine! The store setup had not been changed. only  
the  
the nginx conf file should be adjusted. any sugestions?

to be more specific: in the root folder there is an index.php file were  
magento is set to run the website via mage run code. In the root folder  
there are subfolders one for each store. these folders each contain an  
index.php file were the store is set. any more info needed?

Any help would be appreciated.

additional info: in the root folder there is an index.php file were  
magento  
is set to run the website via mage run code. In the root folder there  
are  
subfolders: one for each store. These folders each contain an index.php  
file  
were the store is set( again via mage run code) (the stores are being  
set  
correctly in these files).

the nginx conf looked like this:

server {

listen 80 default;  
server\_name [website.com](http://website.com);  
root /www\_folder;  
client\_max\_body\_size 10M;

location / {  
index index.php;  
try\_files $uri $uri/ @handler;  
expires 30d;  
}

location /mage/ {  
try\_files $uri $uri/ @magehandler;  
expires 30d;  
}

location @handler {

## Remove trailing slash

rewrite ^/(.\*)/$ /$1 permanent;

## Magento uses a common front handler

rewrite / /index.php;  
}

location @magehandler {

## Adds a trailing slash to any urls that is missing a trailing slash

rewrite ^(.\*[^/])$ $1/ permanent;

## Magento uses a common front handler

rewrite /mage/ /mage/index.php;  
}

## These locations would be hidden by .htaccess normally, protected

location ~  
(/mage/(app/|includes/|lib/|pkginfo/|var/|errors/local.xml|shell/|tmp/|cron.+)|/.git/|/.ht.+)  
{deny all;}

location ~\* .(js|css|png|jpg|jpeg|gif|ico)$ {  
expires max;  
log\_not\_found off;  
}

location /. { ## Disable .htaccess and other hidden files  
return 404;  
}

location ~ .php/ {  
rewrite ^(.\*.php)/ $1 last;  
}

location ~ .php$ {  
add\_header X-UA-Compatible ‘IE=Edge,chrome=1’;  
try\_files $uri =404;  
expires off;  
fastcgi\_index index.php;  
fastcgi\_pass unix:/var/run/php5-fpm.sock;  
#fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
fastcgi\_param SERVER\_PORT 80;  
fastcgi\_param HTTPS $fastcgi\_https;  
}  
}

Posted at Nginx Forum:

> **[Nginx Magento multistore configuration](https://forum.nginx.org/read.php?2,260265,260265#msg-260265)**
>
> There is a website that has multiple subcatogories which are stores in magento: www.website.com/sub1 www.website.com/sub2 www.website.com/sub3 The server used is ngnix. everything is set up. And used to work, the nginx conf file for this site need to...

---

<div class="post-metadata">

**Author:** ![J\_12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@J\_12](https://www.ruby-forum.com/u/J_12)\
**Post date:** [July 14, 2015, 1:23am UTC](https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664/2 "2015-07-14T01:23:29Z")

</div>

I have a feeling that you may be taking the wrong approach… there is  
no need to use these subfolders for each storefront any more.

Each separate storefront has an unique type / code pair, which needs to  
be passed to Magento to identify the site you’re using. I find the  
simplest way to set it up is to map a couple of variables:

Here’s a completely untested example which should ensure that the right  
storefront is used… nothing else necessary

map $request\_uri $mage\_type {  
default store;  
~^/site1 website;  
~^/site2 website;

}

map $request\_uri $mage\_code {  
default default;  
~^/site1 site1;  
~^/site2 site2;  
}

And then your php block would be…

location ~ .php$ {  
add\_header X-UA-Compatible ‘IE=Edge,chrome=1’;  
try\_files $uri =404; expires off;  
fastcgi\_index index.php;  
fastcgi\_pass unix:/var/run/php5-fpm.sock;  
fastcgi\_param SCRIPT\_FILENAME $document\_root$fastcgi\_script\_name;  
include /etc/nginx/fastcgi\_params;  
fastcgi\_param SERVER\_PORT 80;  
fastcgi\_param HTTPS $fastcgi\_https;  
fastcgi\_param MAGE\_RUN\_CODE $mage\_code;  
fastcgi\_param MAGE\_RUN\_TYPE $mage\_type;  
}

On 14/07/15 10:03, J\_12 wrote:

> asked i.e. [www.website.com/sub1/product](http://www.website.com/sub1/product) this returned a “page not found”
> 
> magento is set to run the website via mage run code. In the root folder
> 
> client\_max\_body\_size 10M;  
> expires 30d;
> 
> ## Adds a trailing slash to any urls that is missing a trailing slash
> 
> rewrite ^(.\*.php)/ $1 last;  
> include /etc/nginx/fastcgi\_params;  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)  
> –  
> Steve H. BSc(Hons) MIITP  
> [http://www.greengecko.co.nz](http://www.greengecko.co.nz)  
> Linkedin: [Steve Holdoway - Robotron New Zealand Limited | LinkedIn](http://www.linkedin.com/in/steveholdoway)  
> Skype: sholdowa

---

<div class="post-metadata">

**Author:** ![J\_12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@J\_12](https://www.ruby-forum.com/u/J_12)\
**Post date:** [October 14, 2015, 1:56pm UTC](https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664/3 "2015-10-14T13:56:48Z")

</div>

thanks for your helping. I have had the same issue with configuration

---

<div class="post-metadata">

**Author:** ![J\_12](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/a5b964/32.png) [@J\_12](https://www.ruby-forum.com/u/J_12)\
**Post date:** [November 26, 2015, 7:27am UTC](https://www.ruby-forum.com/t/nginx-magento-multistore-configuration/242664/4 "2015-11-26T07:27:44Z")

</div>

Thanks for this immediate help.
