0

I know that there are other questions with similar topics, but I can't find a solution anywhere that solves my specific problem. The difference here is multiple domains with different sites.

I have Nginx set up with multiple domains: example1.com and example2.com. There's also the "default" host files that have the "Welcome to Nginx!" default web page.

I've tried a few different configurations including:

# 1
server {
   server_name example2.com www.example2.com;
   listen 80;
   return 301 https://example2.com$request_uri;
}
server {
    server_name example2.com www.example2.com;
    listen 443 default_server;

    ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

# 2
server {
    server_name example2.com www.example2.com;
    listen 80;
    listen 443

    return 301 https://example2.com$request_uri;

    ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

}

1 results in:

  • http://example2.com redirecting to https://example2.com showing the "Welcome" page
  • http://example1.com redirecting to https://example2.com showing the "Welcome" page
  • https://example1.com showing the actual content of example1.com

2 results in:

  • http://example2.com with a redirect loop
  • https://example2.com with a redirect loop
  • http://example1.com redirecting to http://example2.com with a redirect loop
  • https://example1.com showing the actual content of example1.com

I can't put the content for example2.com in the default "Welcome" folder or it would affect example1.com.

3
  • 1
    The results you are getting are consistent with the configurations you have shown. Option (1) has no root directive and will therefore point https://example2.com to the nginx default page, and option (2) redirects to itself. Sep 7, 2018 at 12:50
  • What is the behavior that you actually want? Sep 7, 2018 at 13:24
  • What I’m hoping for is http:// example2.com > https:// example2.com and http:// example1.com > https:// example1.com
    – a3k4
    Sep 7, 2018 at 17:07

1 Answer 1

0

Thanks to Richard Smith, I know know how I messed it up. I hadn't included the root locations correctly. Here's the correct files in case it can help someone else:

# example2.com.conf:
server {
    server_name example2.com www.example2.com;
    listen      80;
    return      301 https://example2.com$request_uri;
    # What I was missing:
    root            /var/www/example2-com;
}
server {
    server_name     example2.com www.example2.com;
    listen      443 ssl;# default_server;

    # What I was missing:
    root            /var/www/example2-com;

    ssl_certificate /etc/letsencrypt/live/example2.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example2.com/privkey.pem;
    include         /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam     /etc/letsencrypt/ssl-dhparams.pem;

}

# example1.com.conf:
server {
    server_name example1.com www.example1.com;
    listen      80;
    return      301 https://example1.com$request_uri;

    # What I was missing:
    root            /var/www/example1-com;
}
server {
    server_name     nerd.ink www.nerd.ink;
    listen      443 ssl; # default_server;

    # What I was missing:
    root            /var/www/example1-com;

    ssl_certificate /etc/letsencrypt/live/example1.com/fullchain.pem; 
    ssl_certificate_key /etc/letsencrypt/live/example1.com/privkey.pem;
    include         /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam     /etc/letsencrypt/ssl-dhparams.pem;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .