Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 2
Running Multi-store under centos / php-fpm and nginx? 
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

Hello everyone.

I am at my wits end on trying to get multi-store to work for magento under nginx and php-fpm on CentOS 6.3 and wanted to know if anyone else out there has Magento working with NGINX and multi-stores?

I am sure i am just missing a step or overlooking something…

i have my primary URL set

http://admin.mydomain.com/

This i where Magento was installed under and how we access the Admin area and everything works great!

We have several stores created for our sites

store.mydomain01.com
store.mydomain02.com
store.mydomain03.com

In the webroot of our server (running centos 6.3 , nginx 1.2.7 and PHP 5.4.11 (fpm-fcgi)

/srv/www/admin_mydomain_com/public_html/
---mydomain01
---mydomain02
---mydomain03

So each store has its own directory and within that an index.php file (in 2nd post)

Now i go into

Configuration --> mydomain01

and i set the UnSecure and Secure base URL as

http://store.mydomain01.com
https://store.mydomain01.com

and i leave all other options set as “Use WebSite” box checked.

As for my Vhost file, store.mydomain01.com:

server {
    listen 80
;
    
listen 443;
    
ssl_certificate             /etc/nginx/conf.d/mydomain01.com_chain.pem;
    
ssl_certificate_key     /etc/nginx/conf.d/mydomain01.com.key;
    
server_name         store.mydomain01.com;
    
access_log         /srv/www/storeadmin_mydomain01_eu/logs/store.mydomain01.com_access.log;
    
error_log         /srv/www/storeadmin_mydomain01_eu/logs/store.mydomain01.com_error.log;
    
root             /srv/www/storeadmin_mydomain01_eu/public_html;
 
    
location {
        index index
.html index.php;     ## Allow a static html file to be shown first
        
try_files $uri $uri/ @handler;     ## If missing pass the URI to Magento's front handler
        
expires 30d;             ## Assume all files are cachable
    
}
 
    
## These locations would be hidden by .htaccess normally
    
location ^~ /app/                { deny all}
    location 
^~ /includes/           { deny all}
    location 
^~ /lib/                { deny all}
    location 
^~ /media/downloadable{ deny all}
    location 
^~ /pkginfo/            { deny all}
    location 
^~ /report/config.xml   { deny all}
    location 
^~ /var/                { deny all}
 
    location 
/var/export## Allow admins only to view export folder
        
auth_basic           "Restricted"## Message shown in login window
        
auth_basic_user_file htpasswd## See /etc/nginx/htpassword
        
autoindex            on;
    
}
 
    location  
/. ## Disable .htaccess and other hidden files
        
return 404;
    
}
 
    location 
@handler { ## Magento uses a common front handler
        
rewrite / /index.php;
    
}
 
    location 
~ .php## Forward paths like /js/index.php/x.js to relevant handler
        
rewrite ^(.*.php)/ $1 last;
    
}
     
    location 
~ .php## Execute PHP scripts
        
if (!-e $request_filename{ rewrite / /index.php last## Catch 404s that try_files miss
 
        
expires        off## Do not cache dynamic content
        
fastcgi_pass   127.0.0.1:9000;
        
fastcgi_param  HTTPS $fastcgi_https;
        
fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
[b]        fastcgi_param  MAGE_RUN_CODE mydomain01;
        
fastcgi_param  MAGE_RUN_TYPE store;[/b]
        
include        fastcgi_params## See /etc/nginx/fastcgi_params
    
}
}

Now when i goto the URL store.mydomain01.com i get a 404 page error served out by Magento, not nginx as there is no recorded error in the site error log file.

I guess i just would like some fresh eyes on this before i go absolutely nuts trying to fix this and waste another few weeks reading every article i can find on setting up Magento and every error people have trying to resolve the problem.

 
Magento Community Magento Community
Magento Community
Magento Community
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

This is my index.php file under

/srv/www/admin_mydomain_com/public_html/mydomain01

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.2.0''<')===true{
    
echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>'
;
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT'getcwd());

$compilerConfig MAGENTO_ROOT '../includes/config.php';
if (
file_exists($compilerConfig)) {
    
include $compilerConfig;
}

$mageFilename 
'../app/Mage.php';
$maintenanceFile 'maintenance.flag';

if (!
file_exists($mageFilename)) {
    
if (is_dir('downloader')) {
        header
("Location: downloader");
    
else {
        
echo $mageFilename." was not found";
    
}
    
exit;
}

if (file_exists($maintenanceFile)) {
    
include_once dirname(__FILE__) . '../errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage
::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

[b]/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE''mydomain01';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE''store';[/b]

Mage
::run($mageRunCode$mageRunType);
 
Magento Community Magento Community
Magento Community
Magento Community
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

reading over this thread hoping to maybe find something useful

http://www.magentocommerce.com/boards/viewthread/7931/P15/

seems some others asked about using nginx in a multi-store set up, but even magento isnt.. or wasnt then..

Is it just something that wont work properly?

I really prefer to use nginx for performance, but i know Apache 2.4.4 has direct php-fpm access now…

 
Magento Community Magento Community
Magento Community
Magento Community
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

any chance of getting a simplistic guide like this for nginx, since it doesnt use htaccess files?

http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup

 
Magento Community Magento Community
Magento Community
Magento Community
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

that’s not very reassuring…

I would hope that with Magento themselves running the entire site under nginx they could help the free community with guide on how to do this.

I have already been playing with this for over a month.

Is there any insight you can share on how you got your working with multi-store?

send me in the right direction at least?

i spent about 4 hours yesterday reading every result Google found for me that had magento nginx in the content and some looked promising but didn’t get the site working for me yet.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagenX
Enthusiast
 
Total Posts:  791
Joined:  2008-05-26
Dublin
 

@VanquishTech
this is not a poetic forum… lol

@WPNHost
you can easily connect php-fpm to apache 2.

but i think you missed the point - first of all you have to check error log, see why nginx/php can not take your page.

then
you have to map your store code, simple way like this:

http {
....
## Multi domain configuration
map $http_host $storecode { 
store
.mydomain01.com  code01;
store.mydomain02.com  code02;
store.mydomain03.com  code03;
       
}

.....

server {
.....
location ~ .php{

 
## Store code with multi domain
        
fastcgi_param  MAGE_RUN_CODE $storecode;
        
fastcgi_param  MAGE_RUN_TYPE store## or website;

.....

dont forget to make sure you run store or website;

i think this should work.

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagenX
Enthusiast
 
Total Posts:  791
Joined:  2008-05-26
Dublin
 

oh my GOD…
that poor guy just asking about simple nginx config…

hehe i love your style…

 
Magento Community Magento Community
Magento Community
Magento Community
 
S Macfarlane
Member
 
Avatar
Total Posts:  53
Joined:  2010-10-24
Southampton
 

WPNHost, the last reply from MagenX is exactly what you need and proberly the simpler version you will find on the internet of how to setup store codes for each multistore that are held by PHP-FPM.

 
Magento Community Magento Community
Magento Community
Magento Community
 
WPNHost
Jr. Member
 
Total Posts:  16
Joined:  2012-11-27
 

Yes, i wasn’t at all interested in SEO or any of that, our stores are specific to our sites and only accessible from our sites client. i understand trade secrets and all that, but all i was curious in was to get multi-stores working with nginx.

Thanks for the info for the configs.

In the end, i got it up and running… in 2 days, and about $20 in food, sure it wont rank for SEO currently as we don\’t need it to.. but it works

8 stores
9 seperate URLs all in HTTPS (8 stores and 1 admin)
9 directories in the web root (srv/www/)
8 index.php files with the store code set in each index.php for the stores
8 ln -s skin/media/js/app links to the main root install (admin)

not how i wanted to do it, but with the store in the root website it kept saying it could not find app/mage.php and i kept getting 404\’s when editing files manually.

So this is working so far, just having problem with the bronto plugin now not verifying and giving me a 503 :(

 
Magento Community Magento Community
Magento Community
Magento Community
 
GregC
Sr. Member
 
Avatar
Total Posts:  76
Joined:  2007-11-23
A^2, MI
 

I’ve run into this before as well. Since nginx does not use the .htaccess file for setting environment variables, if you do not have access to the nginx config files, you can accomplish the equivalent of the .htaccess settings by editing the index.php file in the magento root directory.

So before the final line in the file, add in the following lines to detect and set the proper store codes. 

For example -

$hostname $_SERVER['SERVER_NAME'];
$mageRunType="website";

switch (
$hostname{
    
case "wholesale.domain.com":
    
        
$mageRunCode "wholesale";
        break;
        
    case 
"www.domain.com":
    default:
    
        
$mageRunCode "base";
}

Mage
::run($mageRunCode$mageRunType);

Remember the run codes are are the ones you created when setting up the stores in Magento.

Greg

 
Magento Community Magento Community
Magento Community
Magento Community
 
GregC
Sr. Member
 
Avatar
Total Posts:  76
Joined:  2007-11-23
A^2, MI
 

Sorry - double post

 
Magento Community Magento Community
Magento Community
Magento Community
 
ontarget
Jr. Member
 
Total Posts:  5
Joined:  2013-07-18
 

Okay So I am in the dark and looking for more light.

We have Magento Enterprise and hosted on Peer1.com

The server installed is running nginx
The instructions I got from Magento to create a Mult -website only help me if I run apache
I am looking for some instruction on how do I access Nginx and what do I change to make this see my two different website.
I set up the back end in Magento like the instruction said
Since there is no .htaccess what do I do?

All that peer1 said is they want to charge me $150 an hr to look into it but wont quote me on time. I really could use you guys.

http://216.65.12.146/ base ( default)
http://216.65.12.147/

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagenX
Enthusiast
 
Total Posts:  791
Joined:  2008-05-26
Dublin
 

hi
read my post above, or look at the full config on github,
all you need to know is store’s codes.

peer1 is a nasty company, they offer full service package with magento optimized servers,
but actually you get just a box with lots of ram and backported software with castrated configs....
and no real support, i mean magento support....

for the money you pay, they have to send you a personal trainer and a team of technicians to your doorstep ...

cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
serpyre
Enthusiast
 
Avatar
Total Posts:  771
Joined:  2013-05-20
 

MagenX - Peer1 are a top tier enterprise class hosting company, opinions and facts can be very different, small business mindsets where time trumps experience (bottom-up) cannot understand the nuances of enterprise class where experience trumps time (top-down). They are different approaches for different market segments and that should be kept in mind when making these statements.

ontarget - Nginx is complex to set up, apache is easy to set up but complex to make perform well. As stated, Peer1 are a top tier hosting company and it is not unreasonable. It sounds like you need managed hosting rather than a do-it-youself, Nexcess provide enterprise class managed and we also do with the platform we run on. If you need something cheaper then SimpleHelix, Crucial are the next level down. When you host with enterprise class companies you are placing yourself in the top tiers of website hosting, they gained this knowledge from experience and that comes at a price. $150/hr is the going rate for enterprise experience, it is around the same consulting rate that the enterprise companies we work with charge. If you need an up and running solution immediately on this type of platform we can put you in contact with a company who provide enterprise class hosting with clusters (but only if you are the direct end client).

You are using Shopper which is one of the best and also one of the slowest themes due to the ajax calls, along with the fact that you are paying $15,000 for EE. It is better you do it properly from the outset, unless of course you are the service provider for the store, then the bottom-up time approach is going to work its magic while you try and figure out over the coming months how all the components interact with each other, and that is never good for the end client.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ontarget
Jr. Member
 
Total Posts:  5
Joined:  2013-07-18
 

Thank you guys for the comments. My point is we were sold a turnkey solution and now its not. Its more money, time and work with another company? I got peer 1 to send me some help over the weekend. Ill just keep on creating tickets as i move through this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ontarget
Jr. Member
 
Total Posts:  5
Joined:  2013-07-18
 

Support: make a copy of magento.conf and edit the information to match your second store ip.

Okay so I opened it and edited it
Do I add the new Ip and duplicate these lines

server_name 216.65.12.147;
root /var/www/magento2;

If i create a new config file where do i put it?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2