简体   繁体   English

PHP-FPM可以创建slow.log但不能将内容写入slow.log

[英]PHP-FPM can create slow.log but can`t write content into the slow.log

Today, I want to enable the slow-logs with PHP-FPM , and then I configured some parameters into the php-fpm.conf . 今天,我想用PHP-FPM启用慢速日志,然后我在php-fpm.conf配置了一些参数。 In the end, I have a problem, it can create the slow-log, but can't write any contents into the slow-log. 最后,我有一个问题,它可以创建慢日志,但不能将任何内容写入慢日志。 Can someone help me, thanks a lot? 有人可以帮助我,非常感谢吗?

My website is running in Docker, and my Nginx use Unix Sockets to communicate with PHP-FPM , and Nginx running as Root 我的网站在Docker中运行,我的Nginx使用Unix套接字PHP-FPM通信, NginxRoot身份运行

location ~ \.php$ {
   try_files $uri =404;
   fastcgi_pass unix:/var/run/php-fpm7.sock;
}

My php-fpm.conf is 我的php-fpm.conf

[www123]
user = app
group = app
listen = /var/run/php-fpm7.sock
listen.owner = app
listen.group = app
listen.mode = 0666

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

slowlog = /app/logs/my_slow_log/$pool.log.slow
request_slowlog_timeout = 1s

Next step, I created the directory app/logs/my_slow_log and restart the PHP-FPM. 下一步,我创建了目录app/logs/my_slow_log并重新启动PHP-FPM。 It created the file www123.log.slow in directory app/logs/my_slow_log , but the file permission/user/group is wrong. 它在目录app/logs/my_slow_log创建了文件www123.log.slow ,但文件权限/用户/组是错误的。 It was 600 / root / root 它是600 / root / root

/app/logs/my_slow_log # ls -al
total 4
drwxr-xr-x    2 app      app             28 May 16 19:32 .
drwxrwxrwx    3 app      app           4096 May 16 19:00 ..
-rw-------    1 root     root             0 May 16 19:32 www123.log.slow

There are some running processes 有一些正在运行的进程

app/logs/my_slow_log # ps -ef
PID   USER     TIME   COMMAND
    1 root       0:00 runsvdir /etc/service
    7 root       0:00 runsv nginx
    8 root       0:00 runsv javabridge
    9 root       0:00 runsv php7
   10 root       0:00 java -jar /usr/lib/jvm/java-1.8-openjdk/jre/lib/ext/JavaBridge.jar SERVLET_LOCAL:8080
   11 root       0:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf -g daemon off;
   12 root       0:00 {php-fpm7} php-fpm: master process (/etc/php7/php-fpm.conf)
   13 root       0:00 nginx: worker process
   14 root       0:00 nginx: worker process
   15 root       0:00 nginx: worker process
   16 root       0:00 nginx: worker process
   22 app        0:00 {php-fpm7} php-fpm: pool www123
   23 app        0:00 {php-fpm7} php-fpm: pool www123

I find the master php-fpm process was run as Root , but the child process was run as app , so I modified the php-fpm.conf change 我发现主php-fpm进程是以root身份运行的,但子进程是以app运行的,所以我修改了php-fpm.conf更改

user = root
group = root
listen.owner = root
listen.group = root

then restart PHP-FPM, I got some error message 然后重启PHP-FPM,我收到一些错误信息

ERROR: [pool www123] please specify user and group other than root
ERROR: FPM initialization failed

It can't work as Root . 它不能像Root一样工作。 I think the problem was /app/logs/my_slow_log/www123.log.slow created by PHP-FPM master process with root , and my child process was user app , so it can't write anything into the slow-log. 我认为问题是由PHP-FPM主进程用root创建的/app/logs/my_slow_log/www123.log.slow ,而我的子进程是用户应用程序 ,因此它无法在慢速日志中写入任何内容。

I didn't know what truly happened, can anybody help me? 我不知道究竟发生了什么,有人可以帮助我吗? Thanks. 谢谢。

你可以使用这个命令(chmod 777 my_slow_log),我认为Log目录权限并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM