basmariot
By:
basmariot

Two domains on one droplet: static website and node app. Only showing one!

April 20, 2017 440 views
Nginx Deployment Ubuntu 16.04

I need some help setting up multiple domains on one digital ocean droplet.
I have one node.js application running on my droplet. This one is working fine.
I have now tried to add another (static) website with another domain to this droplet, by following the following two tutorials:
https://www.digitalocean.com/community/tutorials/how-to-set-up-nginx-server-blocks-virtual-hosts-on-ubuntu-14-04-lts
https://www.digitalocean.com/community/tutorials/how-to-set-up-a-host-name-with-digitalocean

Unfortunately, when trying to access the second domain in the browser, it shows the node application I first set up. There is a problem with linking the right website files to the second domain. I have the feeling it might be to do with my root folder (or the path to it), as I did not exactly follow the defaults in the tutorial.

My sites-enabled files look like this at the moment:

The Node application:

server {

        listen 80;

        root /home/Bas/node-application;
        index index.html index.htm;

        server_name www.domain1.com domain1.com;
        return 301 https://$server_name$request_uri;
}

server {
        server_name www.domain1.com domain1.com;
        listen 443 ssl http2;
        ssl_certificate /etc/letsencrypt/live/www.domain1.com.com/fullchain.pe$
        ssl_certificate_key /etc/letsencrypt/live/www.domain1.com.com/privkey.$

        # Include  the SSL configuration from cipherli.st
        include /etc/nginx/snippets/ssl-params.conf;

        location / {
           proxy_pass http://localhost:3001;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-NginX-Proxy true;
           proxy_ssl_session_reuse off;
           proxy_set_header Host $http_host;
           proxy_cache_bypass $http_upgrade;
           proxy_redirect off;
        }
        location ~ /.well-known {
                allow all;
       }
     }

The new website, which I would like to add, but is currently not linked to the domain:

server {
        # Enable HTTP/2
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /home/Bas/domain2;
        index index.html index.htm;

        server_name www.domain2.com domain2.com;
        return 301 https://$server_name$request_uri;

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

I have read a lot of questions on the forum, but can't find the answer to this specific one. Any help would be much appreciated!

1 Answer
hansen April 20, 2017
Accepted Answer

Hi @basmariot

But your second code snippet is redirecting to https, so if you haven't got a configuration block for domain2's https, then Nginx will serve the first https server block.
This is a known Nginx "feature": http://nginx.org/en/docs/http/configuring_https_servers.html#name_based_https_servers

Just remove the return-line or create the https block for domain2 - that should fix it.

  • Thanks, that did the trick! I guess this is what you get when you don't really know what you're doing yet... I'll create the https later, just happy I can finally see the website now.

Have another answer? Share your knowledge.