3

I have my magento website at http://www.domain.com. This is linked to the load balancer with 4+ webserver behind.

I need to set up an url like http://www.front1.domain.com to access directly one of the front office server. But I'm always redirected to the base url.

I want to know if a trick exist to allow having only 1 website, 1 store, with multiple url allowing to bypass or not the load balancer.

  • Nobody else ??? Please assist – dagfr Apr 24 '14 at 15:16
2

You can use SetEnv .htaccess variable to get your office IP and/or Subnet, Set an environment variable, along with a local /etc/hosts entry to the IP of one of the servers on the load Balancer.

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

Take a look at the MAGE_IS_DEVELOPER_MODE, $_SERVER variable already in place in index.php and add SetEnv MAGE_IS_DEVELOPER_MODE to your .htaccess files. The above condition is met and Magento is set into Developer Mode.

With the previous in mind, try something like this in your index.php:

$officeIP = '127.0.0.1'; // Change to office or client requested IP
$code = 'default'; // Change store scope view if needed.
if ($_SERVER['REMOTE_ADDR'] == $officeIP) {
  $config = Mage::getConfig();
  $config->setNode("stores/$code/web/unsecure/base_url", 'http://default-magento-store.com/');    
}

More details on overriding Magento's config:


Another possibility most don't realize as well is to use local.xml to set the values, per environment, while this may not answer your specific question, it may help setting up environments and related.

    <config>

    <stores>
       <default> <!-- store code -->
           <web>
                <unsecure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </unsecure>
                <secure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </secure>
            </web>
       </default>
       <admin>
           <web>
                <unsecure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </unsecure>
                <secure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </secure>
            </web>
       </admin>   
    </stores>

    <websites>
       <base> <!-- website code -->
           <web>
                <unsecure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </unsecure>
                <secure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </secure>
            </web>
       </base>
       <admin>
           <web>
                <unsecure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </unsecure>
                <secure>
                    <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
                </secure>
            </web>
       </admin>
    </websites>

    <default>
       <web>
            <unsecure>
                <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
            </unsecure>
            <secure>
                <base_url><![CDATA[http://default-magento-store.com/]]></base_url>
            </secure>
        </web>
    </default>

<!-- ... Rest of your local.xml -->

</config>

If you are wanting to locally override other config values, you can drop this in index.php before the Mage::run(); or other places in the stack if needed. This will output the entire XML Tree Magento has built of all .xml configuration files.

header("Content-Type: text/xml");
die(Mage::app()->getConfig()->getNode()->asXML());
0

I have a similar setup, just with 2 front nodes, and i do it with a extra header to allow the load-balancer to redirect me to the wanted frontend node. I cannot image how this should be done in magento, beacuase the initial redirect happens in the load balancer, at least in my configuration.

The Problem with the rewrite of www.front1.domain.com to www.domain.com has todo with magento-base-url entries. Only thing i could imagine to solve this is dulicating a storeview and setup this address as front1, but the real problem is the loadbalancer, becuase if you split on magento side, how you do per server ocnfigs if you share the same magento-db between the front-nodes?

.htaccess is also out, becuase then i will have a infinite redirect loop from front1.domain to domain.com and so forth. The only viable option i could imagine is either working with the normal url and a selective redirect (maybe on header basis) in the load balancer or a selective redirect in the load balancer and a cloned website/store/storeview to support different urls for the same shop.

0

If you have 4 web servers sitting behind one load-balancer then, in order to access individual servers, you need to put their IP addresses into your browser directly. This will work if:

  • Your machine and the webserver are within the same firewall.

OR

  • the webservers are open to the internet and have static IPs assigned to them.

Generally, its not the case. Hence, the way that you are suggesting is that u want to create sub-domains on the main domain. So if you are going to do that, modify the A records in the DNS server of your domain and make them like this:

domain.com  {load balancer IP}
www.domain.com {load balancer IP}
server1.domain.com  {SERVER 1 IP}
server2.domain.com  {SERVER 2 IP}
server3.domain.com  {SERVER 3 IP}
server4.domain.com  {SERVER 4 IP}
  • I like this kind of solution, but how to deal with magento core_config_data base url redirections ? – dagfr Apr 14 '14 at 8:28
  • @dagfr I hadn't thought about the URL redirection as I have not done this myself yet, but I think the method described at magentocommerce.com/wiki/1_-_installation_and_configuration/… could be replicated for individual nodes. – Srihari Apr 14 '14 at 9:38
0

Regarding the redirect. There's a configuration option 'Auto-redirect to Base URL' as shown: Auto-redirect to Base URL

If that is set to No, then the Magento store will respond on whatever Host: header it receives and not redirect.

However, it will still use the base URL for writing links. To get around that you either need to change the base URL for a specific sub-store, or you can use something like mod_rewrite or mode_proxy in apache, to fake the host.

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.