使用nginx和ssl进行反向代理后不加载脚本

问题描述 投票:0回答:2

我在我的工作中在服务器上安装了nginx,以便我们可以在我们的应用程序中将它用作ssl的反向代理。我在网上关注了一些文章,用这个创建了一个自签名证书:

 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/cert.key -out /etc/nginx/cert.crt

因此,在/ etc / nginx / sites-available下进行配置并重新启动nginx之后,我遇到了一个问题。

在我的服务器下运行的3个应用程序中的2个似乎工作正常,唯一的“问题”是证书不是来自CA,所以你需要添加一个例外,但我想现在没问题。这两个是node.js app和jenkins。

现在对于第三个应用程序,问题是它没有加载脚本。更准确地说,它们运行在chrome,opera,firefox中,但只有当我点击url右侧的小盾时才允许运行不安全的脚本,如下所示:

enter image description here

现在,我想要实现的是从所有浏览器加载脚本,而无需单击以允许脚本运行。与node.js应用程序一样,脚本默认运行。这个应用程序是由maven,jenkins,docker和骨干的组合构建的。我不是开发的一部分,所以我不知道很多关于应用程序的事情。所以我想知道我是否必须更改maven-docker-backbone中的任何配置,以便脚本可以默认运行,就像使用http时一样。

这是我的应用程序反向代理的配置文件:

server {
    listen 80;
    return 301 https://$host$request_uri;
}

server {

    listen 443;
    server_name mysub.domain.com;

    ssl_certificate           /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key       /etc/nginx/ssl/nginx.key;

    ssl on;
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
    ssl_prefer_server_ciphers on;

    access_log            /var/log/nginx/myapp.access.log;

    location / {

      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;

      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_pass          http://localhost:myport;
      proxy_read_timeout  90;

      proxy_redirect      http://localhost:myport https://mysub.domain.com;
    }
  }

最后,这里是没有ssl的conf文件,它通常运行脚本:

server {
    listen 80;

    server_name mysub.domain.com;

    location / {
        proxy_pass http://127.0.0.1:myport;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

很抱歉这篇长篇文章,请提前感谢您提供任何可能有用的提示。

nginx reverse-proxy
2个回答
2
投票

在我的情况下,并非所有内容都通过https提供。确保所有文件都使用https而不是http。

https_mixed_content_error


0
投票

您需要在API主机上打开CORS。

© www.soinside.com 2019 - 2024. All rights reserved.