How to setup a location in nginx where SCRIPT_FILENAME
is pointing to the current file requested?
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
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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.