HTTPS + IP not redirecting to configured Domain Name and gives "Your connection is not private" [Nginx/Ubuntu]

by Dynamic Remo   Last Updated October 19, 2018 04:00 AM

I am using NGINX for 301 redirects on Ubuntu and reverse proxy for my Web Application and aim is to redirect traffic to non-www url such as https://mywebapplication.example.

So with my current config for NGINX Conf File:

mywebapplication.example -> https://mywebapplication.example
www.mywebapplication.example -> https://mywebapplication.example
http://mywebapplication.example -> https://mywebapplication.example
http://www.mywebapplication.example -> https://mywebapplication.example
192.0.2.123 -> https://mywebapplication.example
http://192.0.2.123 -> https://mywebapplication.example

Works fine but when IP with HTTPS is provided in the URL, I get "Your connection is not private."

https://192.0.2.123 -> Your connection is not private

Here's my NGINX Conf.

server {
    listen 192.0.2.123:80;

    location / {
        proxy_pass "http://localhost:4000/";
        proxy_http_version 1.1;
        proxy_set_header Connection "Keep-Alive";
        proxy_set_header Proxy-Connection "Keep-Alive";
    }
}

server {
    listen 192.0.2.123:80;
    server_name  192.0.2.123 192.0.2.123:4000;
    return       301 https://mywebapplication.example$request_uri;
}

server {
    listen 80 http2;
    listen [::]:80 http2;
    server_name  mywebapplication.example www.mywebapplication.example;
    return       301 https://mywebapplication.example$request_uri;
}

server {
    listen       443 ssl http2;
    server_name  www.mywebapplication.example;
    return       301 https://mywebapplication.example$request_uri;
}

server {
    listen 443 ssl http2 default_server;
    listen [::]:443 ssl http2 default_server;
    server_name mywebapplication.example;
    ...
    ...
    ...
    ...
}

How can I handle IP with HTTPS to a successful 301 redirection?

https://192.0.2.123 -> https://mywebapplication.example



Related Questions



nginx redirect http to https not working

Updated April 05, 2015 21:00 PM

Redirect HTTP to HTTPS with WWW in Nginx

Updated January 20, 2017 14:00 PM

Can't redirect http:// to https:// via nginx

Updated August 22, 2017 09:00 AM

nginx won't redirect http to https

Updated November 13, 2017 20:00 PM