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 ?
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.
It's because HTTPS uses port 443. So just add another
listen
statement like this: