用nginx反向代理处理跨域问题
2017/10/5小于 1 分钟约 291 字
前言
博客一直用的七牛cdn做图床,最近启用了https,就出现了这个Mixed Content的提示。连安全小锁都没有了,这怎么能忍?
Mixed Content: The page at 'https://vistazx1.top/xxx' was loaded over HTTPS, but requested an insecure image 'http://xxxx/ssl-config.PNG'. This content should also be served over HTTPS.nginx 配置文件
比较简单,接下来只要替换图片链接就ok。
此处有个小坑 : 如果你写的是proxy_pass http://xxx 实际上是访问了http://xxx/images/xxxx.jpg 如果写的是proxy_pass http://xxx/ 就可以访问http://xxx/xxxx.jpg
location /images/ {
proxy_pass http://xxx/;
}想多了,怎么可能这么简单。这种情况下如果访问 http://blog/images/fun/qwe.jpg 就会404。 我们需要一个rewrite规则,把http://blog/images/images/xxxx/qwe.jpg 替换成http://xxx/fun/qwe.jpg 下面的正则表达式即可解决此问题.
location ^~/images/{
rewrite ^/images/(.*)$ /$1 break;
proxy_pass http://xxx/;
}