donglao9606 2017-03-29 20:44
浏览 168

Nginx 403禁止在PHP文件上使用Location指令

Here's my server block:

server {
    listen       80;
    server_name  localhost;

    root /www/html;
    index index.php;

    location = / {
        autoindex on;
        index index.php;
        try_files $uri $uri/ =404;
    }

    location ~*\.(css|js|gif|jpe?g|png)$ {
        root /www/html/shared;
        rewrite ^/releases(.*)$ $1 last;
        expires 5m;
    }

    location ~* \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }
}

Right now, doing this will just spit out a "403 Forbidden" error when I attempt to access "localhost/". However, the page works perfectly fine if I access it directly-- "localhost/index.php". I can't for the life of me figure out why. The error.log doesn't give me any helpful info nor an error code either--only that the page is "forbidden". Here's the thrown error:

2017/03/29 14:37:35 [error] 11980#8840: *94 directory index of "C:/www/html/" is forbidden, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost"

This is a windows-based nginx server.

  • 写回答

1条回答 默认 最新

  • dongpenggan6812 2017-03-30 18:29
    关注

    the answer was kind of disappointing to discover, but i'm gonna answer it so if anyone encounters this goofy issue they can fix it.

    php was lookng for files with the prefix "/www/html", NOT "/www/html/", as a result when it wanted my index it was trying to load "/www/htmlindex.php" instead of "/www/html/index.php".

    you can fix this by doing either

     fastcgi_index /index.php;
    

    or adding a / to the end of your root.

    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧