Nginx redirect https://ip to https://domain

Freedo asked:

I have a script that is out of my control, that creates links that redirect to my server IP but with https:// on it.

This obviously create issues with the certificate. I can redirect my ip to http://domain fine but I can’t make ip > https://domain work?

server {
    listen 80;

    return 301 $scheme://$request_uri;

server {
    listen 443 ssl;

    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_trusted_certificate /etc/letsencrypt/live/;

    return 301$request_uri;

After that block I have another server {} listening on port 80 and 443 but with server_name using my domain if that matters.

I redacted my IP’s obviously I’m using real IP’s in my configuration file

My answer:

You can’t get a TLS certificate for an IP address that browsers will recognize. You will have to fix the script which generates the inappropriate redirects. That actually is possible.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.