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

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 a multi-site, multi-store, multi-store view environment there is always the complexity of scaling.

Having a Magento admin on a separate domain enables you to use a separate server for admin actions only.

Based on our experience with large websites, we use such a 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.

So, 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-fixIn 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 the default config has URLs set as frontend ones, you may experience the problem where the admin subdomain redirects to the frontend domain.

Base URL

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

Set the Use Custom Admin URL to Yes and fill in the subdomain.

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 if you plan on using a separate server for it.

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

Did it work?
If it didn’t, please continue reading.

Cookies

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

Under the default store view, make sure the cookie domain matches your 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

So, 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.

In addition, try looking through the official documentation.

Of course, if you need any assistance for your setup, do not hesitate to reach out to us at [email protected]

0 0 vote
Article Rating
Subscribe
Notify of
guest
2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
starlyn
starlyn
4 years ago

Make sure your DNS is properly configured for your frontend as well as for the admin can you expand a little about this? I want to do this but some points are not very detailed