0

I have several domains configured for my websites on my VPS.

What I want to achieve is: If a user enters the IP address of my VPS directly on his/her browser, like this: https://X.X.X.X, I want it to redirect to one of my websites.

I was able to make it work for HTTP (http://X.X.X.X) like this:

server {
    listen       80;
    server_name  IP_OF_MY_VPS;

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

However, if the user enters https://X.X.X.X, it doesn't work. Can someone please help out ?

KazikM
  • 215
  • 1
  • 3
  • 11
Mervin Hemaraju
  • 115
  • 4
  • 14

2 Answers2

2

You need to add a valid https block for the IP address.

However, since you cannot get certificates which can be used with an IP address, you will be left with a URL that gives a SSL error from the browser.

Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • 2
    https://stackoverflow.com/q/2043617 and for example https://www.ssl.com/faqs/order-ssl-tls-certificate-for-ip-address/ seem to indicate that it really depends on the CA if they will issue a certificate for an IP-address but there isn't anything technical that actually prevents them from issuing one. – Bob Dec 21 '20 at 07:58
  • Is there any other way then to redirect the user to my website when they enter the ip address directly in to the browser ? Because my website already has SSL to it. I just need to redirect user when they try to enter the IP address directly in the browser – Mervin Hemaraju Dec 21 '20 at 09:17
  • You need to have a certificate that lists the IP address in Subject Alternate Name field, along with your website's domain name. Your current certificate likely contains the domain name only. – Tero Kilkanen Dec 22 '20 at 19:02
1

It's because HTTPS uses port 443. So just add another listen statement like this:

server {
    listen       80;
    listen       443;
    server_name  IP_OF_MY_VPS;

    return       301 https://example.com$request_uri;
}
Noel Nemeth
  • 111
  • 7