client_header_timeout 7d;
client_body_timeout 7d;
send_timeout 7d;
fastcgi_connect_timeout 7d;
fastcgi_read_timeout 7d;
fastcgi_send_timeout 7d;
分类目录归档:Nginx
开启 php-fpm 状态页及 pm.status_path 状态详解
说明
php-fpm 和 nginx 一样,内建了个状态页,可以通过该状态页了解监控 php-fpm 的状态。
具体
1. 在 php 的安装目录下的 www.conf 中打开 pm.status_path 配置项。如:我的 php 安装目录为 /www/source/php,则 www.conf 文件位于 /www/source/php/etc/php-fpm.d/www.conf;将此文件中的 pm.status_path = /status 前的分号去掉,修改成如下:

默认情况下为 /status,当然你也可以改成 /phpfpm_status 等等。这里我修改成 bcstatus
特别说明:你的服务器配置文件不一定叫 www.conf ,请根据自己的配置设置;也可以直接把 pm.status_path = /bcstatus 添加到 php-fpm.conf 中,但是,一定要添加到 php-fpm.conf 文件中的最后,否则重启php-fpm时会出现以下错误:
[24-Mar-2017 16:18:44] ERROR: [/www/source/php/etc/php-fpm.conf:126] unknown entry 'pm.status_path' [24-Mar-2017 16:18:44] ERROR: failed to load configuration file '/www/source/php/etc/php-fpm.conf' [24-Mar-2017 16:18:44] ERROR: FPM initialization failed
2. nginx 配置
在 nginx 的配置文件中添加以下配置。
server { ...... # 在 server 中添加以下配置 location = /bcstatus { include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $fastcgi_script_name; } ..... }
特别说明:这里的 location 最后用 = 号,如我的配置 location = /bcstatus ,因为 = 的优先级最高,如果匹配成功后,就不会再匹配其它选项了。
3、重启 nginx、php-fpm 使配置生效
# /etc/init.d/nginx restart # /etc/init.d/php-fpm restart
重启后用浏览器访问 http://你的域名/bcstatus 就可以看到效果,如:

pm.status_path 参数详解
pool – fpm池子名称,大多数为www process manager – 进程管理方式,值:static, dynamic or ondemand. dynamic start time – 启动日期,如果reload了php-fpm,时间会更新 start since – 运行时长 accepted conn – 当前池子接受的请求数 listen queue – 请求等待队列,如果这个值不为0,那么要增加FPM的进程数量 max listen queue – 请求等待队列最高的数量 listen queue len – socket等待队列长度 idle processes – 空闲进程数量 active processes – 活跃进程数量 total processes – 总进程数量 max active processes – 最大的活跃进程数量(FPM启动开始算) max children reached - 进程最大数量限制的次数,如果这个数量不为0,那说明你的最大进程数量太小了,请改大一点。 slow requests – 启用了php-fpm slow-log,缓慢请求的数量
pm.status_path 显示样式
php-fpm 状态页的显示效果,可以有 json、xml、html、full 四种,可以通过 GET 传参显示不同的效果。
1、json 格式
通过访问 http://你的域名/bcstatus?json 来显示 JSON 格式,如:

2、xml 格式
通过访问 http://你的域名/bcstatus?xml 来显示 JSON 格式,如:

3、html 格式
通过访问 http://你的域名/bcstatus?html 来显示 JSON 格式,如:

4、full 格式
通过访问 http://你的域名/bcstatus?full 来显示 JSON 格式,如:

5、full 显示项
pid – 进程PID,可以单独kill这个进程. state – 当前进程的状态 (Idle, Running, …) start time – 进程启动的日期 start since – 当前进程运行时长 requests – 当前进程处理了多少个请求 request duration – 请求时长(微妙) request method – 请求方法 (GET, POST, …) request URI – 请求URI content length – 请求内容长度 (仅用于 POST) user – 用户 (PHP_AUTH_USER) (or ‘-’ 如果没设置) script – PHP脚本 (or ‘-’ if not set) last request cpu – 最后一个请求CPU使用率。 last request memorythe - 上一个请求使用的内存
原文链接:https://blog.csdn.net/ffzhihua/article/details/88844259
Chrome 每个浏览器只支持6个并发链接
🤣
Nginx + PHP-FPM 边运行边输出
<?php
//apache方法,需要关闭apache缓冲区
for($i=0;$i<1000;$i++){
echo $i;
ob_flush();//刷新PHP自身缓冲区
flush();//刷新(特指apache)web服务器的缓冲区,输出数据
sleep(1);
}
//nginx缓冲区
ob_end_clean();
ob_implicit_flush();
header('X-Accel-Buffering: no'); // 关键是加了这一行。
for($i=0;$i<1000;$i++){
echo $i;
sleep(1);
}
感谢仙士可 http://www.php20.cn/article/159
- X-Accel_Redirect : 由上游服务指定nginx内部重定向 控制请求的执行
- X-Accel-Limit-Rate: 由上游设置发往客户端速度限制 等同于limit_rate指令
- X-Accel-Buffering:由上游控制是否缓存上游的响应
- X-Accel-Charset:由上游控制 Content-Type中的Charset
nginx的worker_processes优化
client_max_body_size、post_max_size、upload_max_filesize
Syntax: | client_max_body_size size; |
---|---|
Default: | client_max_body_size 1m; |
Context: | http , server , location |
post_max_size = 128M; php的post最大大小限制
upload_max_filesize = 128M; php的单个文件大小的限制
PHP里通常需要3者结合才能解除文件上传大小限制。
nginx: [emerg] host not found in upstream
服务器启动的时候dns解析失败,host直接绑定域名是一个解决方案,但是这样不太好
可怕的KCFErrordomainCFNetWork
Nginx 快速解决静态文件POST 405 Not Allowed
error_page 405 =200 $uri;
produced an unexpected error: ‘ascii’ codec can’t decode byte 0xe9 in position
把配置文件里的中文字符串删除就好了
- $ sudo grep -r -P ‘[^\x00-\x7f]’ /etc/apache2 /etc/letsencrypt /etc/nginx
- 將看到的內容,全部進去檔案刪除
- 刪除這些編碼後,在重新執行 Let’s encrypt script 就可以通過囉~
Attempting to renew cert (www.xxx.com) from /etc/letsencrypt/renewal/www.xxx.com.conf produced an unexpected error: 'ascii' codec can't decode byte 0xe9 in position 5: ordinal not in range(128). Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/m.xxx.com/fullchain.pem (failure)
/etc/letsencrypt/live/www.xxx.com/fullchain.pem (failure)
参考链接:https://blog.longwin.com.tw/2019/01/letsencrypt-ascii-codec-decode-fixed-2019/