开发者

Nginx does not redirect php files

Every file is passed to "index.php", but every php file isn't properly redirected because of the fastcgi. Any workaround ?

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

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

    break;
}

location ~* \.php$ {
    include fas开发者_高级运维tcgi_params;

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

Thanks


  1. Make sure the root directory for your php source file is: /usr/share/nginx/html / else, modify the fastcgi_pass ..

This is a working configuration I have:

    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;
}

It will redirect all requests that do not exist and would normally return a 404 error to the index.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜