0

I am a noob when it comes to Linux and nginx, so my question maybe as basic as it sounds.

So I have two domains domain1.com and domain2.com both pointing to my server. I have obtained a certificate via letsencrypt for each of the two. How can I install each of those for each of the domains?

I have searched the internet and had no luck. So far I came up with this

Config 1:

server {
    server_name domain1.com;

    ssl_certificate path/to/cert;
    ssl_certificate_key path/to/cert/key;
}

Config two:

server {
    server_name domain2.com;

    ssl_certificate path/to/cert2;
    ssl_certificate_key path/to/cert/key2;
}

The default config:

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

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

    root /var/www/html;
}

I have created one for both. One doamin was already configured and works fine. But the second can not reach domain2.com via https:// and also the domain points to the default side.

TL;DR How can I use two certificates for two domains on one nginx instance?

Thanks!

EDIT: All other configs are pretty much the basic ones you get with the installation.

  • Create a second server block for your second domain? – Gerald Schneider Dec 6 '17 at 13:25
  • Sorry I have two seperate files with the same content the one above is only a sample of wath I did. One file for each domain. – Andy Schneider Dec 6 '17 at 13:26
  • Then provide all relevant configuration parts for both domains. The given information is not even enough to speculate. – Gerald Schneider Dec 6 '17 at 13:28
  • Sorry I am new. I have edited the post so both configs are present now. Both are located in sites-enabeld and are therefore imported by the default one. – Andy Schneider Dec 6 '17 at 13:30
1

You need to add bindings to each of the server blocks:

listen myipaddress:443 ssl http2;

The first site is catching the traffic. You can use the same IP but just need to check that the nginx version supports SNI (should do if a recent version)

  • Thank you, when checking the config with nginx -t it tells me that http2 is an invalid parameter. What shall i do? – Andy Schneider Dec 6 '17 at 14:35
  • Drop out the http2, it's not essential to what you are trying to do, it's just a nice to have. Should be fine with the rest – John Fox Dec 6 '17 at 14:37
  • Thank you unfortunately i can not upvote your answer. – Andy Schneider Dec 6 '17 at 14:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.