1.初装错误
报以下错误:
sbin/nginx -c conf/nginx.conf
报错内容:sbin/nginx: error while loading shared libraries: libpcre.so.1:
cannot open shared object file: No such file or directory启动时报异常 error while loading shared libraries: libpcre.so.1: cannot openshared object file: No such file or directory 这说明我们的环境还不满足要求,需要小小的配置一下。
解决方法(直接运行):
32 位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib
64 位系统 [root@sever lib]# ln -s /usr/local/lib/libpcre.so.1 /lib64
然后执行 ps -ef | grep nginx 查看 nginx 进程确认是否真的已经启动了,在进程列表里会有最起码两个, worker(nginx 工作进程)和 master(nginx 主进程)
root 4349 1 0 02:24 ? 00:00:00 nginx: master process sbin/nginx -c conf/nginx.conf nginx 4350 4349 0 02:24 ? 00:00:00 nginx: worker process root 4356 28335 0 02:30 pts/1 00:00:00
查看nginx的运行状态,就会发现已正常运行。
PS查看状态命令:
--------------------------------------------------------------------------------
2、Nginx 502 Bad Gateway 错误
在 php.ini 和 php-fpm.conf 中 分 别 有 这 样 两 个 配 置 项 : max_execution_time 和request_terminate_timeout
这两项都是用来配置一个 PHP 脚本的最大执行时间的。当超过这个时间时,PHP-FPM 不止会终止脚本的执行,还会终止执行脚本的 Worker 进程。所以 Nginx 会发现与自己通信的连接断掉了,就会返回给客户端 502 错误。
以 PHP-FPM 的 request_terminate_timeout=30 秒时为例,报 502 Bad Gateway 错误的具体信息如下:
1)Nginx 错误访问日志:
2023/09/19 01:09:00 [error] 27600#0: *78887 recv() failed (104: Connection reset by peer) while reading response header from upstream,client: 192.168.1.101, server: test.com, request: "POST /index.php HTTP/1.1", upstream: "fastcgi://unix:/dev/shm/php-fcgi.sock:", host: "test.com", referrer: "http://test.com/index.php"
2)PHP-FPM 报错日志:
WARNING: child 25708 exited on signal 15 (SIGTERM) after 21008.883410 seconds from start
所以只需将这两项的值调大一些就可以让 PHP 脚本不会因为执行时间长而被终止了。request_terminate_timeout 可以覆盖 max_execution_time, 所以如果不想改全局的 php.ini,那只改 PHP-FPM 的配置就可以了。
此外要注意的是 Nginx 的 upstream 模块中的 max_fail 和 fail_timeout 两项。有时 Nginx 与上游服务器(如 Tomcat、FastCGI)的通信只是偶然断掉了,但 max_fail 如果设置的比较小的话,那么在接下来的 fail_timeout 时间内,Nginx 都会认为上游服务器挂掉了,都会返回 502 错误。
所以将 max_fail 调大一些,将 fail_timeout 调小一些就可以了。