分类目录归档:Nginx

certbot renew: ImportError: cannot import name constants

certbot renew
An unexpected error occurred:
ImportError: cannot import name constants
Please see the logfile ‘/tmp/tmpl4isIP/log’ for more details.

Installing snapd

With the EPEL repository added to your CentOS installation, simply install the snapd package:

$ sudo yum install snapd

Once installed, the systemd unit that manages the main snap communication socket needs to be enabled:

$ sudo systemctl enable --now snapd.socket

To enable classic snap support, enter the following to create a symbolic link between /var/lib/snapd/snap and /snap:

$ sudo ln -s /var/lib/snapd/snap /snap

Remove certbot-auto and any Certbot OS packages

If you have any Certbot packages installed using an OS package manager like apt, dnf, or yum, you should remove them before installing the Certbot snap to ensure that when you run the command certbot the snap is used rather than the installation from your OS package manager. The exact command to do this depends on your OS, but common examples are sudo apt-get remove certbot, 

sudo dnf remove certbot, or sudo yum remove certbot.

If you previously used Certbot through the certbot-auto script, you should also remove its installation by following the instructions here.

Install CertbotRun this command on the command line on the machine to install Certbot.

sudo snap install --classic certbot

Prepare the Certbot commandExecute the following instruction on the command line on the machine to ensure that the certbot command can be run.sudo

ln -s /snap/bin/certbot /usr/bin/certbot

Choose how you’d like to run Certbot

Either get and install your certificates…Run this command to get a certificate and have Certbot edit your Nginx configuration automatically to serve it, turning on HTTPS access in a single step.

sudo certbot --nginx

Or, just get a certificateIf you’re feeling more conservative and would like to make the changes to your Nginx configuration by hand, run this command.

sudo certbot certonly --nginx

Test automatic renewalThe Certbot packages on your system come with a cron job or systemd timer that will renew your certificates automatically before they expire. You will not need to run Certbot again, unless you change your configuration. You can test automatic renewal for your certificates by running this command:

sudo certbot renew --dry-run

The command to renew certbot is installed in one of the following locations:

  • /etc/crontab/
  • /etc/cron.*/*
  • systemctl list-timers

开启 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

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_end_flush() 也可以
ob_implicit_flush(); // 打开绝对刷送
header('X-Accel-Buffering: no'); // 告诉nginx直接输出
# 以上3个一起组合即可实现直接输出
for($i=0;$i<1000;$i++){
    echo $i;
    sleep(1);
}

nginx超时配置参见:

感谢仙士可 http://www.php20.cn/article/159

  1. X-Accel_Redirect : 由上游服务指定nginx内部重定向 控制请求的执行
  2. X-Accel-Limit-Rate: 由上游设置发往客户端速度限制 等同于limit_rate指令
  3. X-Accel-Buffering:由上游控制是否缓存上游的响应
    Sets the proxy buffering for this connection. Setting this to “no” will allow unbuffered responses suitable for Comet and HTTP streaming applications. Setting this to “yes” will allow the response to be cached.
  4. X-Accel-Charset:由上游控制 Content-Type中的Charset

来源 https://www.cnblogs.com/jackey2015/p/10438123.html

client_max_body_size、post_max_size、upload_max_filesize

Syntax:client_max_body_size size;
Default:client_max_body_size 1m;
Context:httpserverlocation
决定post上传文件大小的上限,1m肯定不够用,设置为0表示不做大小检查

post_max_size = 128M; php的post最大大小限制

upload_max_filesize = 128M; php的单个文件大小的限制

PHP里通常需要3者结合才能解除文件上传大小限制。