簡體   English   中英

php和PHP_SELF的位置

[英]location with php and PHP_SELF

如何在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;
    }
}

在這里我File not found

但是如果我將位置更改為此

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

我究竟做錯了什么?

您需要設置fastcgi_index選項,並使用index.php作為其值。 該索引指令在文件系統中查找索引文件。 因此,嘗試像:

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

索引看到/data/www/test/index.php並進行內部重定向到/index.php,因此請求轉到location ~ \\.php$ ,並傳遞給fastcgi。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM