K
K
KOS_MOS2017-06-07 11:40:06
PHP
KOS_MOS, 2017-06-07 11:40:06

Why does Nginx give the PHP script to download instead of executing when adding a slash to the path?

There is a directory on the site, let's say with the name path, and if you access the address example.ru/path - everything starts up perfectly index.php, which is located in this directory, and if you access it with a slash at the end - example.ru/path / , then index.php is downloaded.
Site config

server
{
  listen 80;
  root /var/www/example.ru;
  index index.html;
  server_name example.ru;

  location ~ \.php$
  {
    include common/php-fpm;
  }
}

common/php-fpm
# Настройки порта или сокета PHP-FPM производятся в файле "/etc/php5/fpm/pool.d/www.conf"
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;

# Порядок важен - строчка "include fastcgi_params" должна быть первой
include fastcgi_params;
fastcgi_split_path_info ^(.+?\.php)(/.*)?$;

# Вместо переменной "$document_root" можно указать адрес к корневому каталогу сервера и это желательно (см. http://wiki.nginx.org/Pitfalls)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;

# См. http://trac.nginx.org/nginx/ticket/321
set $path_info $fastcgi_path_info;
fastcgi_param PATH_INFO $path_info;

# Additional variables
fastcgi_param SERVER_ADMIN [email protected];
fastcgi_param SERVER_SIGNATURE nginx/$nginx_version;
fastcgi_index index.php;

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nurlan, 2017-06-07
@daager

How about adding:
location /{
try_files $uri $uri/index.php /index.php;
}
Like you need it.

K
KOS_MOS, 2017-06-07
@KOS_MOS

News from the front - chrome somehow cached that the file was downloaded o_O - in private mode and in fox it works correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question