[Vuejs]-Serving static file locally on a subdomain

0👍

Let’s start with a bit of terminology correction.

  • http://hostname is not really a domain. It is just a URL referring to
    an unqualified host name. A domain would typically be something like
    yourorgdomain.com (or .org or .edu or other such top level domains;
    let’s stick with .com for now). Your hostname (when fully qualified
    under the domain) would be identified as hostname.yourdomain.com.
    Therefore, your hostname is mapped to a subdomain. For the sake of
    simplicity, if being referred from another host on the same domain
    and network the domain part is implied so the network understands that and something like http://hostname just works. The mapping is somewhere
    in your network configuration.

  • http://hostname/app is not a subdomain of http://hostname; it’s just
    a path (or more correctly a resource) under the same host http://hostname. A subdomain would be something like http://app.hostname http://app.hostname.yourdomain.com when fully qualified)

Now for some explanation of how these URLs work:

Consider the URL http://hostname:50. The http:// part is referring to the protocol and :50 part at the end to the port number. By default http uses port 80 (https uses 443). So if you configure your web server to serve on port 80, the :50 part is redundant.

Now you just need to organize your website content such that it is available at http://hostname/app URL. The simplest way to do this for static sites is to host your content under the /app/... directory relative to where your site root is mapped to. So if your web server is serving the directory .../public on http://hostname, just move your content to .../public/app like you do for file paths. That’s all

Caveats

However, if you truly want to host your app under a subdomain like http://app.hostname/ then that’s a whole different story, but in brief, the lowest level subdomain being referred to (app) has to be mapped to a host and the intermediate subdomain can’t be a host, just a subnet. You can’t have further subdomains under a host. That’s why typically websites addresses refer to http://www.example.com where the www is mapped to the host actually running the website

All of this ignores how reverse proxies and load balancers work and pretend to exhibit this above behavior but that another long story for another day.

Leave a comment