Magento 2 Admin on a Separate (Sub)Domain in a Multi-Site Environment

This entry was posted on January 31, 2020 by Miloš Zlatanović, CTO.

Separate (Sub)Domain

Setting up Magento 2 Admin panel on a separate subdomain should be easy right? If you had problems setting it up, you are not the only one. This article is here to help you resolve this problem once and for all.

Why Would You Use the Subdomain for Magento Admin?

In multi-site, multi-store, multi-store view environment there is always the complexity of scaling.

Having the Magento admin on a separate domain enables you the usage of the separate server only for admin actions.

For example in our experience, in large websites, we use such setup where we move all the cron job actions to the admin server, as well as all the API import actions. This separates the frontend experience from all the heavy computing done in the backend.

Here are some common known problems with the Magento admin domain:

  • Admin subdomain redirects to frontend domain
  • Infinite redirect loop (between admin subdomain and frontend domain)
  • Bugs in early versions of Magento 2.1.x and 2.2.x - This extension used to fix it METMEER/magento2-multi-store-fix. In Magento 2.3.x it is fixed.

Note: Depending on your server configuration, some additional steps could be required but let’s go over Magento’s setup first.

Configuration in the Admin Panel

Make sure you are in the Default Config store view.

If default config has URLs set as frontend URLs you may experience the problem where the admin subdomain redirects to the frontend domain.

Store View

Go to:

Stores > Configuration > General > Web

Base URLs
 

Note: Base URL for Static View Files and for User Media Files may be different in your setup.

In order not to break the frontend URL, make sure you set up your multi-store URLs in their own store views (Stores > Configuration > General > Web).

The last step is to configure Magento to actually use a subdomain as access to it.

Go to:

Stores > Configuration > Advanced > Admin

Admin Base URL

Make sure to set the Use Custom Admin URL to Yes. Below, in the Custom Admin URL fill in your subdomain for the admin panel.

Note: Make sure your DNS is properly configured for your frontend as well as for the admin subdomain. You could use the same IP for both or separate IP addresses for the admin subdomain if you plan on using a separate server for it.

Clear the cache and try your new setup now, preferably in the incognito tab. (Or you may need a deploy)

Did it work?
If not, please continue reading.

Cookies

In some cases, your cookies might be blocking you from accessing the new admin subdomain.

Under the default store view, make sure the cookie domain matches your admin domain. But also make sure you set the proper domain in your website scope.

Is it working?
If not, you may need to check your environment setup.

Environment

Here are some questions that could help you.

  • Have you tried it in the incognito tab? Or flushing the browser cache?
  • Do you have a load balancer? Is the new subdomain flowing through the load balancer?
  • Are you on Nginx? - Check your proxies.
  • Or Apache maybe? - Check your .htaccess files.
  • Are DNS settings ok? Are the domains pointing to the right addresses?
  • Do you get redirected? - Try one of the redirect tracing tools for your browser.

 

Try looking through the official documentation:

https://docs.magento.com/m2/ee/user_guide/stores/store-urls-custom-admin.html

If you need any assistance for your setup, feel free to reach out to us at [email protected]

This entry was posted in Magento 2 and tagged Web Development, SyncIt Group, Magento 2, Web, Magento 2 Development, Admin Panel, Admin Panel Configuration, Magento 2 Admin, Separate Subdomain, Separate Domain, Multi-Site, Multi-Site Environment, Environment Setup, Base URL, Admin Base URL on January 31, 2020 by Miloš Zlatanović, CTO .