I have an application deployed to various IP addresses (e.g., http://a.b.c.d). I want to embed this application inside a website secured with SSL (https). Directly embedding the IP address in an iframe causes browsers to throw a mixed content warning.
To solve this, I set up an Nginx reverse proxy with an internal URL (https://mywebsite.com/ecs/1) pointing to the IP address (http://a.b.c.d). Here is the Nginx configuration that works perfectly:
location /ecs/1/ {
proxy_pass http://a.b.c.d:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
}
Now, I need the reverse proxy to be dynamic since the IP addresses keep changing. I rewrote my proxy config to handle any IP address:
location /ecs/ {
rewrite ^/ecs/(?<site>[^/]+)/? http://$site:8000;
proxy_pass http://$site:8000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
}
This should allow https://mywebsite.com/ecs/a.b.c.d to proxy to a.b.c.d:8000. While the proxy works and redirects correctly, the page still throws a mixed content warning and the iframe doesn’t load.
Is there a way to dynamically proxy HTTP to HTTPS using Nginx without triggering mixed content warnings, considering that getting an SSL certificate for each IP address is impractical?
Constraints:
- Obtaining SSL certificates for each IP address is impractical.
Any help or guidance on resolving this issue would be greatly appreciated!
I’ve tried:
- Static proxy configuration (works without warnings but isn’t dynamic).
- Dynamic proxy configuration (throws mixed content warnings).
Akhil Rasheed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.