How to have https on two domain names pointing at the same IP?

  1. configuration file /etc/nginx/sites-enabled/wellword.conf:
server {
    # listen on port 80 (http)
    listen 80;
    server_name wellword.ru;
    location / {
        # redirect any requests to the same URL but on https
        return 301 https://$host$request_uri;
    }
}
server {
    # listen on port 443 (https)
    listen 443 ssl;
    server_name _;

    # location of the self-signed SSL certificate
    ssl_certificate /etc/letsencrypt/live/wellword.ru/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wellword.ru/privkey.pem;

   # ssl_certificate /etc/letsencrypt/live/keyword.pictures/fullchain.pem;
   # ssl_certificate_key /etc/letsencrypt/live/keyword.pictures/privkey.pem;
  1. configuration file /etc/nginx/sites-enabled/keyword.pictures.conf:
server {
    # listen on port 80 (http)
    listen 80;
    server_name keyword.pictures;
    location / {
        # redirect any requests to the same URL but on https
        return 301 https://$host$request_uri;
    }
}
server {
    # listen on port 443 (https)
    listen 443 ssl;
    server_name _;

    # location of the self-signed SSL certificate
   # ssl_certificate /etc/letsencrypt/live/wellword.ru/fullchain.pem;
   # ssl_certificate_key /etc/letsencrypt/live/wellword.ru/privkey.pem;

    ssl_certificate /etc/letsencrypt/live/keyword.pictures/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/keyword.pictures/privkey.pem;
2 Likes

@Rip or @rg305

Cleanup on previous post, please!

6 Likes

All done. :slightly_smiling_face:

(20 characters :roll_eyes: )

8 Likes

Guys, I added the server name 'wellword.ru' to this section (and "keyword.pictures" to another .conf file) and it looks wellword.ru works fine now.
But www.wellword.ru still pointing at keyword.pictures cert.

2 Likes

Both the port 80 and port 443 server blocks for wellword.ru should have:

server_name wellword.ru www.wellword.ru;

The same applies for keyword.pictures.

Don't forget to reload nginx after making the changes:

sudo nginx -s reload

7 Likes

Even if you don't use Ubuntu, this is practically invaluable:

6 Likes

Thank you a lot! Now HTTPS works on both domain names.
Thank you for the article too! There is an Ubuntu 18 on the server and it is what I plan to move forward next (add another but static page)

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.