I currently have my e-commerce site (ZenCart) installed at one domain (I’ll call it www.mydomain.com) and that domain is served via Cloudflare’s DNS. My admin backend is www.mydomain.com/backend. What I wanted to do is serve the front end through Cloudflare (orange cloud icon), but serve the backend via straight processing on a subdomain (grey cloud icon). (This is because when I run certain backend scripts, Cloudflare always drops the connection and serves an error (1016, I believe) despite me increasing my server timeouts or increasing the worker count). (In short, if I remove the domain from Cloudflare or pause Cloudflare’s processing on that domain, it works… with no problem. But if I turn Cloudflare back on… OOPS.)
My question is: does anyone know how to set up the server to serve that one directory via a subdomain? I know I’m going to have to change the configuration of the ZenCart script, but I’m not sure what else needs to be changed.
I tried to create a sub-server of the main server, but for some reason, the Server refuses to point at the right directory.
I have never done this, but it should work in theory: on your ZenCart virtual server, create an alias. The alias domain must not have anything to do with Cloudflare. Now, you will be able to access your ZenCart website on its usual domain via Cloudflare and you will also be able to access your ZenCart website on the alias domain - but not via Cloudflare.
So use the alias domain for all your admin back-end work.
So it has to be an alias subdomain? Should I change the document root of the alias to point to the directory that contains the backend script or is it enough for me to just use backend.mydomain.com\backend?
Okay so here’s a weird one, could “Website Proxy Settings” also work? That is, create a subserver, but proxy it to the directory of the main virtual server?
Nix that. The method mentioned by calport works. Just would need to do a few extra changes.
An alias does not have a document root of its own. It is the same document root as the parent.
And, an alias is a better/safer solution than having a cPanel style Subdomain, where the subdomain lives in a directory in the parent domain, as you’ve initially asked about.
I guess I was more or less trying to ask, how to point the root of a subserver inside the directory of another server I guess. (I know using subdomains isn’t recommended or advised but I didn’t have a better word to use for it.)
“subdomain” only means what you’ve described if you’re using an old version of cPanel. No one else calls it that. We used to support that type of “subdomain” in Virtualmin, but it always felt so terrible. I’ll note that cPanel apparently also doesn’t do it that way anymore (I don’t know for sure, I’ve just been told by people who used cPanel in recent years).
But, an alias is pointing inside the directory of another server. It is exactly the same content as the parent. If you want what’s in a subdirectory, just include the subdirectory in your URL.
If you have an application that needs special treatment for /api for instance, just make an alias of api.domain.tld and change the path to:
https://api.domain.tld/api
That’s it. You’re done. Don’t make it complicated or confusing and weird or potentially a security issue.
If you really wanted to make it appear on https://api.domain.tld without the subdirectory in the path, you could do a RewriteRule with a RewriteCond on the HTTP_HEADER to point to the subdirectory…still an Alias, it just behaves differently and doesn’t serve everything, only the subdirectory.