如何仅在一台主机上在Nginx配置中设置php ini设置 [英] How to set php ini settings in nginx config for just one host

查看:88
本文介绍了如何仅在一台主机上在Nginx配置中设置php ini设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以这样在nginx.conf中设置error_reporting:

fastcgi_param   PHP_VALUE   error_reporting=E_ALL;

但是,如果我在一个服务器块中执行此操作,是否还会影响所有其他服务器?我是否应该同时更改所有服务器块中的php设置?

But if I do this in one server block, will it affect all the others as well? Should I change php settings in all server blocks simultaneously?

推荐答案

如果服务器上的每个主机都在其自己的PHP-FPM池中运行,则将fastcgi_param PHP_VALUE ...添加到一个nginx主机不会影响其他主机.

If every host on your server runs in its own PHP-FPM pool, than adding fastcgi_param PHP_VALUE ... to one nginx host will not affect the other ones.

另一方面,如果所有nginx主机都使用一个PHP-FPM池,则应为每个拥有的主机指定PHP_VALUE(其中一个为error_reporting=E_ALL,其他为空).因为fastcgi_param通过PHP_VALUE(如果指定),并且不通过.一段时间后,除非您在其他主机中显式设置了PHP_VALUE,否则所有工作进程都将具有PHP_VALUE=error_reporting=E_ALL.

If on the other hand all nginx hosts use one PHP-FPM pool, you should specify PHP_VALUE for every host you have (error_reporting=E_ALL for one of them, empty value for others). Since fastcgi_param passes PHP_VALUE if specified, and doesn't pass if not. In a while all workers will have PHP_VALUE=error_reporting=E_ALL, unless you explicitly set PHP_VALUE in other hosts.

另外,fastcgi_param PHP_VALUE ...个声明会相互覆盖(最后一个生效).

Additionally, fastcgi_param PHP_VALUE ... declarations override one another (the last one takes effect).

复制步骤:

  1. 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;
    }
}

  • s1s2添加到/etc/hosts

  • Add s1, s2 to /etc/hosts

    /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)
    

  • 这篇关于如何仅在一台主机上在Nginx配置中设置php ini设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆