Answer the question
In order to leave comments, you need to log in
nginx. How to give 404 when accessing .php files?
The site structure is as follows:
/var/www/site/web
/var/www/site/src The index.php file, which is located in the web folder, is
used as a single entry point .
All other php files of the project are located in src .
When accessing any address in the browser that ends with .php (for example httр://site.ru/src/config.php or httр://site.ru/sdvasdfasfdasdf.php ), the error "500 Internal Server Error nginx" appears .
How to make it so that instead of 500 a 404 page is given?
My settings:
server {
listen 80;
server_name site.ru;
root /var/www/site/web;
index index.php;
error_page 404 /404.php;
location / {
try_files $uri /index.php;
}
location ~ \.php$ {
try_files $uri = /404.php;
fastcgi_index index.php;
fastcgi_pass fpm:9000;
fastcgi_param SCRIPT_FILENAME $request_filename;
include fastcgi_params;
}
}
location ~ \.php$ {
root /var/www/site/src;
...
}
Answer the question
In order to leave comments, you need to log in
Most likely the problem is in this line
. There is no such file, so there is a loop.
You need to either add a 404.php file to the root and process the error there, or change this line totry_files $uri =404
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question