How to set php ini settings from nginx for only one host

It can be set error_reportingin nginx.confthis way:

fastcgi_param   PHP_VALUE   error_reporting=E_ALL;

But if I do this in one server block, will it affect everyone else? Should I change php settings on all server blocks at the same time?

+4
source share
2 answers

If each host on your server runs in its own PHP-FPM pool, adding fastcgi_param PHP_VALUE ...nginx to one node will not affect the others.

, , nginx PHP-FPM, PHP_VALUE (error_reporting=E_ALL , ). fastcgi_param PHP_VALUE, , , . PHP_VALUE=error_reporting=E_ALL, PHP_VALUE .

, fastcgi_param PHP_VALUE ... ( ).

:

  • apt install nginx php5-fpm

  • /etc/nginx/sites-enabled/hosts.conf:

    server {
        server_name  s1;
        root  /srv/www/s1;
        location = / {
            include  fastcgi.conf;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_param  PHP_VALUE  error_reporting=E_ERROR;
        }
    }
    
    server {
        server_name  s2;
        root  /srv/www/s1;
        location = / {
            include  fastcgi.conf;
            fastcgi_pass  unix:/var/run/php5-fpm.sock;
        }
    }
    
  • s1, s2 /etc/hosts

  • pm static, pm.max_children 1 /etc/php5/fpm/pool.d/www.conf

  • cat /srv/www/s1/index.php:

    <?php var_dump(error_reporting());
    
  • systemctl restart php5-fpm && systemctl restart nginx

  • curl s2 && curl s1 && curl s2

    int(22527)
    int(1)
    int(1)
    
+2

PHP_VALUE , . PHP PHP_VALUE, .

(debian), /etc/nginx/conf.d/php_settings.cnf:

fastcgi_param PHP_VALUE "upload_max_filesize=5M;\n error_reporting=E_ALL;";

:

server {
  ...
  location ~ \.php$ {
    ...
    include /etc/nginx/conf.d/php_settings.cnf;
  }
  ...
}
+4

All Articles