Subdomains pointing to same droplet in different ports?

Posted January 5, 2014 17.4k views
Hi, we would like to have 3 subdomains resolving to the same IP (same droplet) but pointing to 3 different servers that will be running on it. The servers were developed in GO programming language (golang). One domain will be the API serving on port X: Other one will be our Admin Dashboard on port Y: And the last one will be our website running probably on port Z: How can we config the DNS to accomplish our desired setup? Can you help us with that? Thank you very much in advance.
1 comment

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.

Submit an Answer
2 answers
Firstly, create a DNS record for each of the subdomains. The DNS records tell the browser which server/IP address it should connect to. Browsers assume port 80 by default.

In order to map each subdomain to a different port, you will need to use a reverse proxy such as nginx.

You will need to insert this into each virtualhost instead of the virtualhost config in the said article.
  • Hi kamaln7

    I need same setup. Unfortunately your second link does not work (any more). Could you please explain again what would be the difference to direct to a subdomain?

    Thanks, Alex

by Justin Ellingwood
When using the Nginx web server, server blocks (similar to the virtual hosts in Apache) can be used to encapsulate configuration details and host more than one domain off of a single server. In this guide, we'll discuss how to configure server blocks in Nginx on an Ubuntu 16.04 server.