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

求一个 nginx 配置

  •  
  •   mxm145 · 2021-09-26 14:51:29 +08:00 · 1751 次点击
    这是一个创建于 914 天前的主题,其中的信息可能已经有所发展或是发生改变。
    求一个 nginx 配置,需求如下:网站的目录结构是 /html/年 /栏目名 /稿件 id,现在需要屏蔽,地址类似: https://example.com/html/2016/news/1.html,现在需要屏蔽 2016 年整年的稿件,除了某个栏目的,就是: https://example.com/html/2016/news/1.html 不能打开,但是 https://example.com/html/2016/ok/2.html 可以打开,就是要匹配到栏目名称是 ok 的,可以打开
    4 条回复    2021-09-26 15:16:41 +08:00
    InDom
        1
    InDom  
       2021-09-26 14:55:30 +08:00
    盲写的哈,不知道对不对。

    location ~ ^/html/2016/(news|health)/ {
    return 403;
    }
    mxm145
        2
    mxm145  
    OP
       2021-09-26 14:58:22 +08:00
    关键是需要屏蔽的栏目很多,不可能全写出来,最好是能匹配到可以放行的栏目名就放,其他的一律屏蔽
    @InDom
    alvinbone88
        3
    alvinbone88  
       2021-09-26 15:09:15 +08:00
    location /html/2016/ {
    return 403;
    }

    location /html/2016/ok/ {
    // 自定义配置
    }
    mxm145
        4
    mxm145  
    OP
       2021-09-26 15:16:41 +08:00
    @alvinbone88 测试确实可以实现,但是要把顺序反过来放,多谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3146 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 12:32 · PVG 20:32 · LAX 05:32 · JFK 08:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.