【问题标题】:Nginx does not redirect php filesNginx 不重定向 php 文件
【发布时间】:2011-04-15 19:37:06
【问题描述】:

每个文件都被传递给“index.php”,但由于 fastcgi,每个 php 文件都没有正确重定向。任何解决方法?

location / {
    if ($request_filename ~* "index.php") {
        break;
    }

    rewrite ^/(.*)$ /index.php?page=$1 last;

    break;
}

location ~* \.php$ {
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
    fastcgi_pass 127.0.0.1:9000;
}

谢谢

【问题讨论】:

    标签: php nginx rewrite


    【解决方案1】:
    1. 确保你的php源文件的根目录是:/usr/share/nginx/html/否则,修改fastcgi_pass..

    这是我的工作配置:

        location /media {
        if (-f $request_filename) {
                 # filename exists, so serve it
            break;
        }
    
        if (-d $request_filename) {
                 # directory exists, so service it
            break;
        }
        rewrite ^/(.*)$ /media/index.php?$1;
    }
    

    它将重定向所有不存在的请求,并且通常会向 index.php 返回 404 错误

    【讨论】:

      猜你喜欢
      • 2015-09-03
      • 2018-10-30
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-20
      • 2016-11-07
      相关资源
      最近更新 更多