0

I am having trouble running one node app and one static page (just html) on two seperate domains at the same time. No matter what I tried the static domain gets always redirected to the node app (on port 3000)

Here are the "sites-available" files :

Node App :

server {
    listen [::]:80;
    listen 80;


server_name www.domain1.com domain1.com;

# and redirect to the https host (declared below)
return 301 https://domain1.com$request_uri;
}

server {
    listen 443;
    server_name domain1.com www.domain1.com;

    ssl on;
    # Use certificate and key provided by Let's Encrypt:
    ssl_certificate /etc/letsencrypt/live/domain1.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/domain1.com/privkey.pem;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';


    location / {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $http_host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-NginX-Proxy true;
            proxy_pass http://localhost:3000/;
            proxy_ssl_session_reuse off;
            proxy_set_header Host $http_host;
            proxy_cache_bypass $http_upgrade;
            proxy_redirect off;
    }
}

And the static one :

server {
    listen [::]:80;
    listen 80;


   #server_name www.domain2.com domain2.com;

   root /var/www/html/domain2;
   index index.html index.htm;


   return 301 https://domain2.com$request_uri;
}

server {

   listen [::]:443 ssl;
   listen 443 ssl;

   root /var/www/html/domain2;

   index index.html index.htm;

   ssl_certificate /etc/letsencrypt/live/domain2.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/domain2.com/privkey.pem;
}

The default config file is empty. Any help/hint would be greatly appreciated.

It worked fine until I generated a Let's encrypt certificate for domain2, put both domains in seperate configs and removed the default.

Thank you in advance!

2
  • Have you installed the symlink to sites-enabled? Commented Aug 11, 2016 at 14:52
  • Hey Richard, thanks for the comment. Yes the symlink is installed. Commented Aug 12, 2016 at 8:39

1 Answer 1

1

The problem is that you have no server_name directive in your static domain configuration. As a result, the request is always caught by your default server block, which appears to be your node app.

See for details:

Sign up to request clarification or add additional context in comments.

1 Comment

VBart, thank you very much! Problem solved! Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.