AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1090575
Accepted
TravelWhere
TravelWhere
Asked: 2022-01-20 20:43:07 +0800 CST2022-01-20 20:43:07 +0800 CST 2022-01-20 20:43:07 +0800 CST

重定向在 nginx 上导致 404 错误

  • 772

如果用户尝试仅在浏览器中直接访问图像文件,我该如何重定向?我仍然希望保留允许社交媒体网站通过热链接嵌入我们的图像的能力。我只希望用户通过浏览器直接访问图像进行重定向。

这是我的 nginx 配置文件

proxy_cache_path /var/www/img.example.com/htdocs/cache-store levels=1:2 keys_zone=pixstore:10m max_size=5g inactive=7d use_temp_path=off;
server {

    server_name img.example.com www.img.example.com;

    access_log /var/log/nginx/img.example.com.access.log ;
    error_log /var/log/nginx/img.example.com.error.log;

    add_header X-Proxy-Cache $upstream_cache_status;
    location / {
        proxy_cache pixstore;
        proxy_cache_revalidate on;
        proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
        proxy_cache_lock on;
        add_header X-Cache-Status $upstream_cache_status;
        proxy_pass http://xxx.xxx.xxx.xxx:8090;
        proxy_redirect off;
        include proxy_params;
        proxy_cache_valid 200 7d;
        proxy_cache_valid 404 5m;
    }

    location ~ "^/c/600x1200_90_webp/img-master/img/\d+/\d+/\d+/\d+/\d+/\d+/((?<filenum>\d+)[^/]+\.(jpg|png|webp))$" {
    valid_referers server_names;
    if ($invalid_referer = "0") {
    return 301 http://view.example.com/artwork/$filenum; }
    }

}

nginx错误日志

2022/01/19 12:09:23 [error] 7426#7426: *30 open() "/usr/share/nginx/html/c/600x1200_90_webp/img-master/img/2021/06/09/00/00/05/90423484_p0_master1200.jpg" failed (2: No such file or directory), client: xxx.xxx.xxx.xxx, server: img.example.com, request: "GET /c/600x1200_90_webp/img-master/img/2021/06/09/00/00/05/90423484_p0_master1200.jpg HTTP/1.1", host: "img.example.com"

重定向不起作用,但如果我尝试访问任何图像文件,它会给我一个 404 错误。我将其设置为反向代理站点,因此我没有定义根路径。我怎样才能解决这个问题?

nginx
  • 0 0 个回答
  • 1263 Views

0 个回答

  • Voted
  1. Best Answer
    AlexD
    2022-01-20T23:06:45+08:002022-01-20T23:06:45+08:00

    由于您没有为图像位置定义根路径,nginx因此使用默认路径 - /usr/share/nginx/html/。如果您希望获取这些文件,proxy_pass您还需要将配置复制proxy_pass到此位置。

    • 0

相关问题

  • Gzip 与反向代理缓存

  • nginx 作为代理的行为

  • Nginx 学习资源 [关闭]

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 在 Apache、LightTPD 和 Nginx Web 服务器上提供 PHP 5.x 应用程序的现状?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve