关于weibo/图床图片403无法访问问题

2023年 新浪weibo的图床失效解决方案
更新于: 2023-01-31 09:15:00

几张403的图片

解决方案

可以让 img 访问的办法,添加 referer

curl 'https://wx1.sinaimg.cn/orj480/beebff5fly1h9w0wt38jkj20u01hc41z.jpg' \
  -H 'referer: https://weibo.cn/' \
  --compressed

nodejs 实现转发

yarn add express http-proxy-middleware
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
const app = express();

// add proxy for img.dev.com
app.use(
  "/tvimg",
  createProxyMiddleware({
    target: "https://tva1.sinaimg.cn/",
    changeOrigin: true,
    pathRewrite: {
      "^/tvimg": "",
    },
    // add headers
    headers: {
      referer: "https://www.weibo.cn/",
    },
  })
);

app.listen(5000, () => {
  console.log("Example app listening on port 5000!");
});

另一个解决方案

<img
  src="https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/007S8ZIlgy1gexw87htqhj305k05k74o.jpg"
  alt=""
/>

nginx 反向代理

server {
    listen 80;
    listen 443 ssl;
    server_name dev.com;

    ssl_certificate /etc/letsencrypt/live/dev.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.com/privkey.pem;

    location / {
        # add_header Content-Disposition inline;
        proxy_set_header Referer "https://weibo.cn";
        proxy_pass https://tva1.sinaimg.cn/;
    }
}
ln -s $PWD/nginx/tav1.dev.com.conf /etc/nginx/conf.d
certbot certonly --standalone --email 1290657123@qq.com -d tva1.dev.com

参考