hugohil
By:
hugohil

How do I set up multiple websites on one droplet and configure DNS correctly ?

May 21, 2015 2k views
DNS Nginx Node.js Ubuntu

Hi,

I have a Ubuntu 14.04 droplet, running a nodejs and a nginx server. The nodejs server distribute a website on port 80, and the nginx serves a WordPress on 1337.
I easily binded my domain name to the nodejs server, but am struggling to do the same for my wordpress installation ...
I can't figure out how to bind my domain to a specific port (which apparently is impossible), and I can't think of another way of binding two domains on two servers hosted on the same machine.

Help ? :)

Thank you in advance !

@hugohil

4 Answers

I think what you want to do is have your Wordpress served from nginx on port 80 and set up your node to listen on 1337. Then set up forwarding as per this tutorial.

server {
    listen 80;
    server_name your-domain-name.conf.com;
    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:2368;
    }
}
  • Thank you for your answer @phocks, but I'm still wondering how would I do setup my DNS for the node server ?
    I can't bind it on port 1337, can I ?

  • @hugohil You're not actually binding to 1337 externally. Nginx will process all requests on port 80 and then direct them according to the server_name So you could use something like yourdomain.com for the node app and blog.yourdomain.com for WordPress. Check out this tutorial for some more info: How To Set Up Nginx Server Blocks

    by Justin Ellingwood
    Nginx is an incredibly powerful web server and reverse proxy. In this guide, we'll discuss how to set up server blocks on Ubuntu 14.04 in order to server multiple domains from a single server.

Thanks you very much @asb and @phocks, I finally figured it out !
Thanks to both of your tutorial, I managed to better understand nginx :)

Hi,

I'm in the same situation, but I don't want to use blog.yourdomain.com for the blog.
I would like to use yourdomain.com/blog

is it possible? (I have the nodejs app in yourdomain.com)

Have another answer? Share your knowledge.