如何解决nginx反向代理混合内容(http,https)

新的nginx。 玩了2天,不知道如何解决这个问题:

我有一堆虚拟机运行在一个盒子里,这个盒子显然是在我的路由器后面,其中一个虚拟机正在运行nginx(我的反向代理)并被设置为DMZ。

我已经在该虚拟机上正确安装了SSL证书,现在我希望所有传入的stream量都按照它们的path定向,例如:

domain.com/service1->192.168.1.101

domain.com/service2->192.168.1.102

等等。 想法是让nginx作为SSL层,nginx通过HTTP或任何未encryption的协议与其他VM通信。 当然,当nginx与客户端交谈时,这些消息应该被encryption。

我已经有了部分工作。 如果我通过HTTP访问一切都很好,除非没有encryption,但如果我通过HTTPS访问的网页被破坏,我得到了这样的错误: Mixed Content: The page at 'https://domain.com/service1' was loaded over HTTPS, but requested an insecure stylesheet 'http://domain.com/service1/blahblah.css'. This request has been blocked; the content must be served over HTTPS. Mixed Content: The page at 'https://domain.com/service1' was loaded over HTTPS, but requested an insecure stylesheet 'http://domain.com/service1/blahblah.css'. This request has been blocked; the content must be served over HTTPS.

我也有这样的警告: The page at 'https://domain.com/service1/' was loaded over HTTPS, but is submitting data to an insecure location at 'http://domain.com/service1/': this content should also be submitted over HTTPS. ://domain.com/service1/上The page at 'https://domain.com/service1/' was loaded over HTTPS, but is submitting data to an insecure location at 'http://domain.com/service1/': this content should also be submitted over HTTPS.

现在,对于一些服务我可以破解服务本身,以便它可以得到修复…但我不想这样做,因为那样我就必须破解每个耗费时间并可能破坏某些东西的服务。 我想尽可能less地接触这些服务。

我目前的configuration与黑客工作,但没有黑客无法正常工作。 它涵盖了整个服务1:

 location /service1/ { proxy_pass http://192.168.1.101/; proxy_read_timeout 3500; proxy_connect_timeout 3250; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto https; proxy_set_header SSL_PROTOCOL $ssl_protocol; } 

我环顾了互联网寻找一个通用的解决scheme,但只发现一个服务的黑客工作。 其他nginx的例子/ howtos没有什么帮助(仍然得到错误和警告)。

提前谢谢了!

您必须浏览网站的代码,并将http://domain.com/resource所有出现replace为/resource//domain.com/resource

这确保了所有依赖的网页资源都使用与网站本身相同的协议加载。

这适用于nginx https代理>> nginx http服务Django后端

在位置指令中:

 proxy_set_header X-Forwarded-Proto $scheme; 

有关更多详情,请阅读以下优秀文章: https : //www.metaltoad.com/blog/running-drupal-secure-pages-behind-proxy

settings.php ,设置

 $base_url=''; 

但bootstrap会向你显示错误,所以在/var/www/includes/bootstrap.inc改变下面的代码

 if (isset($base_url)) { //change to if (isset($base_url) && $base_url!='') { 

添加到这个apache.conf文件解决了我的问题

  <IfModule mod_setenvif.c> SetEnvIf X-Forwarded-Proto "^https$" HTTPS </IfModule>