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
mxm145
V2EX  ›  NGINX

求一个 nginx 配置

  •  
  •   mxm145 · Sep 26, 2021 · 2697 views
    This topic created in 1677 days ago, the information mentioned may be changed or developed.
    求一个 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 replies    2021-09-26 15:16:41 +08:00
    InDom
        1
    InDom  
       Sep 26, 2021
    盲写的哈,不知道对不对。

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

    location /html/2016/ok/ {
    // 自定义配置
    }
    mxm145
        4
    mxm145  
    OP
       Sep 26, 2021
    @alvinbone88 测试确实可以实现,但是要把顺序反过来放,多谢
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2455 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 04:10 · PVG 12:10 · LAX 21:10 · JFK 00:10
    ♥ Do have faith in what you're doing.