简体   繁体   English

php和PHP_SELF的位置

[英]location with php and PHP_SELF

How to setup a location in nginx where SCRIPT_FILENAME is pointing to the current file requested? 如何在nginx中设置SCRIPT_FILENAME指向当前请求文件的位置?

server {
    listen  80;
    server_name  xx.xx.xx.xx;

    location /test {
        root  /var/www/test;
    }

    location ~ \.php$ {
        include  /var/ini/nginx/fastcgi.conf;
        fastcgi_pass  php;
        fastcgi_param  SCRIPT_FILENAME /var/www/test$fastcgi_script_name;
    }
}

Here I get File not found 在这里我File not found

But if I change location to this it works 但是如果我将位置更改为此

fastcgi_param  SCRIPT_FILENAME /var/www/test/index.php;

What am I doing wrong? 我究竟做错了什么?

you need to set fastcgi_index option and use index.php as its value. 您需要设置fastcgi_index选项,并使用index.php作为其值。 This index directive looks up filesystem for index file. 该索引指令在文件系统中查找索引文件。 So try like: 因此,尝试像:

location ~ \.php$ {
    include  /var/ini/nginx/fastcgi.conf;
    fastcgi_pass  php;
    fastcgi_index  index.php; #add this
    fastcgi_param  SCRIPT_FILENAME /var/www/test$fastcgi_script_name;
}

the index sees /data/www/test/index.php and does internal redirect to /index.php, so the request goes to location ~ \\.php$ and is passed to fastcgi. 索引看到/data/www/test/index.php并进行内部重定向到/index.php,因此请求转到location ~ \\.php$ ,并传递给fastcgi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM