V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
zmc
V2EX  ›  NGINX

nginx 怎么根据判断文件是否存在访问不同的路径

  •  
  •   zmc · 2018-08-07 14:38:16 +08:00 · 3226 次点击
    这是一个创建于 2060 天前的主题,其中的信息可能已经有所发展或是发生改变。
    因为磁盘空间满了,无法直接扩容,所以加了一块磁盘,
    现在打算用 nginx 判断文件是否存在,否则查找另一个路径,
    请问使用 nginx 能解决吗,配置文件要怎么配置?
    www.aaa. com/data1/upload/2018/08/07/1.jpg
    www.aaa. com/data2/upload/2018/08/07/1.jpg
    8 条回复    2018-08-07 15:55:26 +08:00
    lihongjie0209
        1
    lihongjie0209  
       2018-08-07 14:41:46 +08:00
    理论上来说属于重定向的一种 nginx 就不是很懂了
    wizardoz
        3
    wizardoz  
       2018-08-07 14:47:05 +08:00
    直接 google nginx 404 redirect to ur
    RobertYang
        4
    RobertYang  
       2018-08-07 14:50:01 +08:00 via Android
    if (!-e $request_filename)
    { rewrite }
    rrfeng
        5
    rrfeng  
       2018-08-07 15:11:45 +08:00
    try_files 了解一下
    est
        6
    est  
       2018-08-07 15:13:47 +08:00
    @rrfeng 正解。try_files。
    zmc
        7
    zmc  
    OP
       2018-08-07 15:45:03 +08:00
    location /upload/ {
    root /data1/project;
    try_files $uri $uri/ /index.html;
    }
    谢谢大家解答,存在第一个$uri 能匹配上,/data1/project/2018/08/07/1.jpg
    如果不存在,那么第二个$uri 要怎么写,/data2/project/2018/08/07/1.jpg
    jswh
        8
    jswh  
       2018-08-07 15:55:26 +08:00   ❤️ 1
    在 data1/project 下软连接 project2 -> /data2/project
    然后
    location /upload/ {
    root /data1/project;
    try_files $uri $uri/ project2/$uri project2/$uri2/ /index.html;
    }

    可能可以
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1517 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:53 · PVG 07:53 · LAX 16:53 · JFK 19:53
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.