ioioioioioioi
V2EX  ›  问与答

Nginx 如何禁止对 index.php 的直接访问

  •  
  •   ioioioioioioi · Dec 19, 2016 · 2603 views
    This topic created in 3458 days ago, the information mentioned may be changed or developed.
    location / {
        try_files   $uri /index.php?$query_string;
    }
    
    7 replies    2016-12-19 21:16:55 +08:00
    lslqtz
        1
    lslqtz  
       Dec 19, 2016   ❤️ 1
    不清楚能不能用。。
    location /index.php {
    return 403;
    }
    ioioioioioioi
        2
    ioioioioioioi  
    OP
       Dec 19, 2016   ❤️ 1
    @lslqtz 不行。
    lslqtz
        3
    lslqtz  
       Dec 19, 2016
    好吧。。不行
    我查查
    lslqtz
        4
    lslqtz  
       Dec 19, 2016
    @ioioioioioioi 没查到,我觉得可以在 php 做限制。。
    设置 index 和 try_files 后,我得到的$uri 变量直接是 index.php 了。。
    lslqtz
        5
    lslqtz  
       Dec 19, 2016
    <?php if ($_SERVER['REQUEST_URI'] == '/index.php') { header('HTTP/1.1 403 Forbidden'); die(); } ?>
    我在 php 用这句可以实现,但是 nginx 没搞懂,如果有人知道怎么解决也顺便艾特我一下 :D
    privil
        6
    privil  
       Dec 19, 2016
    location =/index.php {
    return 403;
    }
    查了下,有优先级的。
    lslqtz
        7
    lslqtz  
       Dec 19, 2016
    @privil 我当时试着使用 location = "/index.php"
    但是无效,因为传过来的参数似乎已经被改写了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5591 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 53ms · UTC 07:34 · PVG 15:34 · LAX 00:34 · JFK 03:34
    ♥ Do have faith in what you're doing.