nginx 502/页面图片加载不出的原因

环境

  • CentOS
  • Docker
    • Nginx
    • Nextcloud:8888
    • Mysql
    • ……

Docker 中的Nginx代理Nextcloud的链接,通过错误代码497,实现了在8888端口支持HTTP和HTTPS。

问题1

然而在使用过程中发现,8888端口监听HTTPS时,如果把nextcloud.conf配置文件中,proxy_pass 写为https://XXX 形式,妥妥出现502错误。(此处是我知道怎么改,但是想不通的地方,如果说是因为nextcloud网站内部的配置导致只支持HTTP,但是我使用http://dockerip:8888是可以访问的)

nextcloud.conf

server {
listen 8888 ssl;
server_name "";
client_max_body_size 10G;
ssl_certificate /etc/nginx/certs/1_iwork.pegrand.com_bundle.crt;
ssl_certificate_key  /etc/nginx/certs/2_iwork.pegrand.com.key;
location / {
proxy_redirect off;
proxy_pass http://nextcloud_web:8888;
proxy_set_header Host $http_host;
}
error_page 497 https://$host:8888$request_uri?$args;
}

问题2

另一个问题就是在使用过程中,所有的logo和登陆界面的背景图片加载不出来。

Error:-Refused to connect to 'http://domain.com/.../logo?v=10' because it violates the following Content Security Policy directive: "img-src 'self' data:  'unsafe-eval'". …………

刚开始以为是Nginx配置问题,没有让HTTP转发到HTTPS上。
后来发现是Content-Security-Policy的问题,找到了问题却苦于没看懂哪段代码控制安全策略,一直没有解决。
直到后来在Nextcloud中安装一个unsplash的应用,自动获取随机登陆背景。查看了一下他的php文件。终于找到关键代码,解决了图片加载不全的难题。开心~~

apps2/unsplash/….app.php

<?php

OCP\Util::addStyle('unsplash', 'login');

$manager = \OC::$server->getContentSecurityPolicyManager();
$policy = new \OC\Security\CSP\ContentSecurityPolicy();
$policy->addAllowedImageDomain('https://source.unsplash.com');
$policy->addAllowedImageDomain('https://images.unsplash.com');
$manager->addDefaultPolicy($policy);

猜你喜欢

转载自blog.csdn.net/yomo127/article/details/78564118