V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
zmc
V2EX  ›  NGINX

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

  •  
  •   zmc · Aug 7, 2018 · 4169 views
    This topic created in 2830 days ago, the information mentioned may be changed or developed.
    因为磁盘空间满了,无法直接扩容,所以加了一块磁盘,
    现在打算用 nginx 判断文件是否存在,否则查找另一个路径,
    请问使用 nginx 能解决吗,配置文件要怎么配置?
    www.aaa. com/data1/upload/2018/08/07/1.jpg
    www.aaa. com/data2/upload/2018/08/07/1.jpg
    8 replies    2018-08-07 15:55:26 +08:00
    lihongjie0209
        1
    lihongjie0209  
       Aug 7, 2018
    理论上来说属于重定向的一种 nginx 就不是很懂了
    wizardoz
        3
    wizardoz  
       Aug 7, 2018
    直接 google nginx 404 redirect to ur
    RobertYang
        4
    RobertYang  
       Aug 7, 2018 via Android
    if (!-e $request_filename)
    { rewrite }
    rrfeng
        5
    rrfeng  
       Aug 7, 2018
    try_files 了解一下
    est
        6
    est  
       Aug 7, 2018
    @rrfeng 正解。try_files。
    zmc
        7
    zmc  
    OP
       Aug 7, 2018
    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  
       Aug 7, 2018   ❤️ 1
    在 data1/project 下软连接 project2 -> /data2/project
    然后
    location /upload/ {
    root /data1/project;
    try_files $uri $uri/ project2/$uri project2/$uri2/ /index.html;
    }

    可能可以
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   925 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 20:37 · PVG 04:37 · LAX 13:37 · JFK 16:37
    ♥ Do have faith in what you're doing.