Symbolic link two domains/subdomains to same directories?


I’m building a site to host on a droplet with a somewhat unconventional file structure and I’m not sure how to go about setting up the files.

Basically, I have two domains: and On domainB, I also have many subdomains for different people. Each subdomain will have its own index, cusomtized with information for each person, but then all of the other pages are the same for each site.

So,,, and will all pull from the same files.

I don’t want a redirect because I want the domain name to stay the same (it will confuse people if it changes).

From research I think symlinks might do what I want, but I really have no clue, and can’t find any documentation on doing something like this (I’m not super familiar with using the command line).

I also want to try and avoid just copying all of the directories to each subdomain for SEO and logistical purposes.

Any help would be much appreciated!!!

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


You can setup location blocks within each NGINX server block that point to the same directory.

For each of the domains and the sub-domain listed, you could use something such as the server block shown below. You’d simply change server_name to match the domain or sub-domain.

Essentially, you’ll create a server block for each domain and sub-domain. So if you have 10 domains and 10 sub-domains, you’ll end up with 20 server blocks, each customized for the domain or sub in question.

server {
    listen 80;

    root /path/to/web/root;

    location / {
        try_files $uri $uri/ =404;

    location /work {
        root /path/to/work/directory;

        try_files $uri $uri/ =404;


The first instance of root defines the web root for the domain. This should be the location where all the main files for the domain exist.

The first location block handles requests for each domain or sub-domain.

The second location block is where we handle serving ./work. We define a second root within this block as we need to specify where requests for ./work will pull from since you don’t want to copy the files to each users directory.

With the above, all you’d really need to do is change server_name to match the domain or sub and then create one for each – copy and paste.

Of course, the above assumes you only want to serve HTML files. If you want to serve PHP, we’d need to setup a PHP block as well. If you want to use NodeJS, Python or another language, we’d have to setup proxy_pass to handle proxying the requests to a port.