nginx/fpm 和 PHP_VALUE 不起作用

nginx/fpm 和 PHP_VALUE 不起作用

我正在尝试更改我的 Web 服务器上单个站点的一些 php.ini 值:

fastcgi_param  PHP_VALUE  "auto_prepend_file=/var/www/profile/external/header.php \n auto_append_file=/var/www/profile/external/footer.php";

但该值被 FPM 完全忽略了。

我尝试在 vhost 配置顶部或下方添加该行位置 ~* .php$ {指令,但均不起作用

这是我在 nginx 下的 vhost 配置:

server {
  listen          80;
  index           index.php index.html;
  server_name     myvisit;
  root            /var/www/mv/head/myvisit/;
  access_log      /var/log/nginx/myvisit-access.log;
  error_log       /var/log/nginx/myvisit-error.log;

  fastcgi_param   PHP_VALUE  "auto_prepend_file=/var/www/profile/external/header.php \n auto_append_file=/var/www/profile/external/footer.php";

  # Use gzip compression
  # gzip_static       on;  # Uncomment if you compiled Nginx using --with-http_gzip_static_module
  gzip                on;
  gzip_disable        "msie6";
  gzip_vary           on;
  gzip_proxied        any;
  gzip_comp_level     5;
  gzip_buffers        16 8k;
  gzip_http_version   1.0;
  gzip_types          text/plain text/css application/json application/x-javascript text/xml application/$

  # error pages
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /var/www;
  }

  # Deny access to hidden files
  location ~* /\.ht {
    deny            all;
    access_log      off;
    log_not_found   off;
  }

  location / {
    try_files $uri $uri/ /index.php?$args;
  }

  location ~* /myvisitv3[-_](.*)\.(?:html|php) {
      try_files $uri $uri/ /myvisitv3.php?libAdresse=$1&$args;
  }

  location ~* /favicon.(?:ico|png|bmp|jpg)$ {
      try_files $uri $uri/ /web/img/favicon.ico;
  }

  # Pass PHP scripts on to PHP-FPM
  include global/php-fpm.conf;
  location ~* \.php$ {
    include /etc/nginx/fastcgi_params;
    try_files       $uri /index.php;
    fastcgi_index   index.php;
    fastcgi_pass    php5-fpm-sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
    fastcgi_param   PHP_VALUE          "auto_prepend_file=/var/www/profile/external/header.php \n auto_append_file=/var/www/profile/external/footer.php";
  }
}

答案1

它不适用于所有 Linux 发行版。有关详细信息,请参阅PHP 错误 #51595

答案2

它对我来说是有效的,但仅限于位置上下文。在服务器上下文中,它的工作方式与预期不同。在 nginx 论坛上讨论:服务器上下文中的 fastcgi_param 不起作用

相关内容