七牛云存储的http资源链接怎么在https站点下使用?

参考:https://www.9myi.com/article/info/29

起因:

Typora图片自动上传用的是七牛云的图床,七牛云的免费http图片在https的网站不显示,七牛云开启https流量收费

解决:

申请免费证书,新建https站点反向代理到七牛云的http图片地址

阿里云申请申请免费DV试用证书

申请免费DV试用证书 - 阿里云帮助文档

照着官方教程做,申请批准也很快,不到半个小时

下载证书

博客是宝塔+Nginx部署

  • 下载证书选Nginx
  • 下载后解压缩得到两个文件

上传部署证书

宝塔面板添加站点

  • 登录宝塔控制面板-网站-添加站点file.qbzzz.top

  • 点击网站名-SSL-其他证书,把证书解压得到的两个文件里的 密钥(KEY)、证书(PEM格式)复制上去-保存-证书夹-部署

访问https://file.qbzzz.top有页面显示则成功

设置反向代理

点击刚创建的https站点-反向代理-添加反向代理

image-20220219073109087

反向代理之后,流量直接打到了Nginx,七牛云图床的cdn加速意义不存在,可以选择开启缓存

  • 宝塔上如果已经有了一个反向代理,修改开启缓存配置不成功,需要删除了反向代理,重新添加反向代理并选上开启缓存

如果不使用宝塔面板的反向代理,在服务器上配置文件如何设置?

宝塔面板的Nginx配置文件

/www/server/nginx/conf/nginx.conf

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

events
    {
        use epoll;
        worker_connections 51200;
        multi_accept on;
    }

http
    {
        include       mime.types;
        #include luawaf.conf;

        include proxy.conf;

        default_type  application/octet-stream;

        server_names_hash_bucket_size 512;
        client_header_buffer_size 32k;
        large_client_header_buffers 4 32k;
        client_max_body_size 50m;

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        limit_conn_zone $binary_remote_addr zone=perip:10m;
        limit_conn_zone $server_name zone=perserver:10m;

        server_tokens off;
        access_log off;

server
    {
        listen 888;
        server_name phpmyadmin;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;
            location ~ /tmp/ {
                return 403;
            }

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {
            expires      30d;
        }

        location ~ .*\.(js|css)?$
        {
            expires      12h;
        }

        location ~ /\.
        {
            deny all;
        }

        access_log  /www/wwwlogs/access.log;
    }
include /www/server/panel/vhost/nginx/*.conf;
}

include /www/server/panel/vhost/nginx/*.conf;

新建的file站点Nginx配置文件

/www/server/panel/vhost/nginx/file.qbzzz.top.conf

server
{
    listen 80;
    listen 443 ssl http2;
    server_name file.qbzzz.top;
    index index.php index.html index.htm default.php default.htm default.html;
    root /www/wwwroot/file.qbzzz.top;

    #SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
    #error_page 404/404.html;
    ssl_certificate    /www/server/panel/vhost/cert/file.qbzzz.top/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/file.qbzzz.top/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;

    #SSL-END

    #ERROR-PAGE-START  错误页配置,可以注释、删除或修改
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END

    #PHP-INFO-START  PHP引用配置,可以注释或修改
    #清理缓存规则

    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$1$is_args$args;
        #access_log  /www/wwwlogs/file.qbzzz.top_purge_cache.log;
    }
    #引用反向代理规则,注释后配置的反向代理将无效
    include /www/server/panel/vhost/nginx/proxy/file.qbzzz.top/*.conf;

    include enable-php-00.conf;
    #PHP-INFO-END

    #REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
    include /www/server/panel/vhost/rewrite/file.qbzzz.top.conf;
    #REWRITE-END

    #禁止访问的文件或目录
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
    {
        return 404;
    }

    #一键申请SSL证书验证目录相关设置
    location ~ \.well-known{
        allow all;
    }

    access_log  /www/wwwlogs/file.qbzzz.top.log;
    error_log  /www/wwwlogs/file.qbzzz.top.error.log;
}
#引用反向代理规则,注释后配置的反向代理将无效
include /www/server/panel/vhost/nginx/proxy/file.qbzzz.top/*.conf;

反向代理配置文件目录;

/www/server/panel/vhost/nginx/proxy/file.qbzzz.top/

反向代理配置文件

#PROXY-START/
location  ~* \.(gif|png|jpg|css|js|woff|woff2)$
{
    proxy_pass http://img.qbzzz.top;
    proxy_set_header Host img.qbzzz.top;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    expires 12h;
}
location /
{
    proxy_pass http://img.qbzzz.top;
    proxy_set_header Host img.qbzzz.top;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;

    add_header X-Cache $upstream_cache_status;

    #Set Nginx Cache

        add_header Cache-Control no-cache;
}

#PROXY-END/

在Nginx(或Tengine)服务器上安装证书

https://help.aliyun.com/document_detail/98728.htm

Typora自动上传图片到七牛云url改成反向代理的https

Typora自动上传图片是http://img开头,放到博客需要换成https://file,如何更自动点呢?

修改Typora上传图片的七牛云配置文件

文件-设置偏好-图像-打开配置文件

把里面的qiniu配置的url:http://img 换成https://file

"qiniu": {
      "url": "https://file.qbzzz.top"
   }

url是自动转换了,但是图片加载很慢

图片本身放服务器 VS 反向代理七牛云http?

渣渣服务器的渣渣带宽,不想给七牛云的图床开https付费的解决方法,目前就这样了。

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注