dsyct08008 2014-10-08 17:41
浏览 577

Nginx如何直接访问index.php时返回404

For security purpose, I am attempting to hide almost all the fingerprint info of my web application. The most important thing is to hide PHP from any visitors. So I try to modify my Nginx's configuration file. The configuration will show as follows.

location / {
        root   /data/site/public;

        index  index.html index.htm index.php;
        try_files $uri /index.php;

        location /index.php {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi.conf;
        }
    }

By this way, I successfully hide index.php from URL. However, Hackers could also directly access my website by using some URL such as http://example.com/index.php, which shows that my website is written by PHP. Sometimes it maybe dangerous. So, I modify the Nginx's config second time, longing for 404 when access index.php directly, and it looks like

location / {
        root   /data/site/public;

        if ( $request_uri ~ /index\.php ) {
            return 404;
        }

        index  index.html index.htm index.php;
        try_files $uri /index.php;

        location /index.php {
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            include fastcgi.conf;
        }
    }

However..., it seems that Nginx acts nothing different from the previous one.

Could anyone tell me the reason ? or any other solutions...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器