Nginx – Disable https when Nginx reverse proxy to IP address

httphttp-serverhttpsnginxreverse-proxy

I configured Nginx as a reverse proxy on my server for a site, say example.com

I want the client to access my site using an IP address, something like http://192.0.2.67

The problem is that there is a redirection on the example.com site setting HTTP to redirect to HTTPS. (This example.com using Cloudflare)
When the client accesses my site from http://192.0.2.67 they are redirected to https://example.com

How do I disable HTTP redirect to HTTPS on my Nginx reverse proxy?

My code is like below :

server {
   listen 80;

   location / {
       proxy_pass http://example.com;
   }
}

Best Answer

I don't see the redirection in the code you have post in the question. It mean that the redirection is done on side example.com.

Depends how is the redirection done. In case the redirection is done simply "http TCP/80 => https TCP/433" and no following checks you can try to proxy directly to https:

server {
   listen 80;

   location / {
       proxy_pass https://example.com;
   }
}

In case this will not help I am afraid you have not much chances to success as you are not the node realizing the force for https redirect.

In case there is HTTP Strict Transport Security (HSTS) header in the page the redirection is done on browser level and there you have also minimal chances to skip ip (in theory you can try to filter out this header).