将nginx代理从https到http获取被阻止加载混合活动内容错误翻译成中文为:“将nginx代理从https到http获取被阻止加载混合活动内容错误”。

我正在使用nginx(openresty),并尝试使用https从公共WAN代理到使用http的私有10网络上的Apache服务器。我尝试代理的应用程序是openscrum。页面加载,但是某些JavaScript(jquery等)正在尝试通过http而不是https传输。使用firebug,我看到了以下错误:

Blocked loading mixed active content "http://privateurl.com/js/jquery-ui-1.9.2.custom.min.js"

我无法想出解决方案,以下是我用于nginx虚拟主机的内容:

upstream SVRLINK {
  server    10.100.200.25;
}
server {
  listen 80;
  server_name   mgt.privateurl.com.com;
  rewrite       ^ https://$server_name$request_uri? permanent;
}
server {
  listen        443 ssl;
  server_name   mgt.privateurl.com.com;

  ssl                   on;
  ssl_certificate         /opt/services/configs/mgt/cert.pem;
  ssl_certificate_key     /opt/services/configs/mgt/key.pem;
  ssl_client_certificate  /opt/services/certs/public_certs/mychain.pem;
  ssl_verify_depth 5;
  # ssl_verify_client on;

  ssl_prefer_server_ciphers on;
  ssl_protocols         SSLv3 TLSv1;
  ssl_ciphers           ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM;
  client_max_body_size 20m;
  error_log   /etc/openresty/nginx/logs/error debug;
  access_log /etc/openresty/nginx/logs/access;

  location / {
    proxy_read_timeout 300;
    proxy_connect_timeout 300;
   # proxy_redirect     off;

    proxy_set_header   X-Forwarded-Proto $scheme;
    proxy_set_header   Host              $http_host;
    proxy_set_header   X-Real-IP         $remote_addr;
    proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;

    proxy_pass http://SVRLINK;
    proxy_redirect http:// https://;
  }
}

有没有什么办法让它工作?感谢您花时间阅读。

点赞
用户2140803
用户2140803

这很可能与您的 nginx 无关,而与 Web 应用程序的 html 有更多关系。

如果他们在脚本和 CSS 标签中硬编码了 http,则经常会看到这些问题。检查前端模板,可以使用协议简短的 URL 这样的好技巧(https://blog.httpwatch.com/2010/02/10/using-protocol-relative-urls-to-switch-between-http-and-https/),

就像这样,它会让浏览器根据页面的服务方式使用 https 或 http。

2015-10-29 02:37:07
用户7724384
用户7724384

你可以尝试将以下代码放在 Apache 站点配置文件的开头(在“VirtualHost”块之外):

SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on

来源

2017-04-24 22:44:35
用户3755133
用户3755133

我可能晚了将近五年,但最近我遇到了这个问题,解决方法是设置 HTML 页面中的:

<base href="/" />

在 Nginx 中设置如下:

proxy_set_header   X-Forwarded-Proto $scheme;
proxy_set_header   Host              $http_host;
proxy_set_header   X-Real-IP         $remote_addr;
proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
proxy_pass http://your_server_host:your_server_port;
2020-01-27 00:46:48