以下是Nginx日志中常见的CentOS错误及对应原因、解决方法:
端口冲突
nginx: [emerg] bind() to 0.0.0.0:80 failed (9: Address already in use)。netstat -tuln | grep <端口>查占用进程,停止冲突服务或修改Nginx端口配置。配置文件语法错误
nginx.conf)存在语法错误。nginx: [emerg] invalid PID file或nginx: [alert] could not build the server_names_hash。nginx -t测试配置文件,修正错误后重启服务。权限不足
nginx)无权访问文件或目录。403 Forbidden错误或nginx: [alert] could not open error log file。chown -R nginx:nginx /path/to/directory和chmod -R 755 /path/to/directory调整权限。后端服务异常(502 Bad Gateway)
[error] connect() failed (111: Connection refused)。systemctl status php-fpm),确保其正常运行并调整超时参数(proxy_connect_timeout等)。资源不足
worker_connections相关错误。free -h、df -h、top查看资源使用情况,优化Nginx配置(如调整worker_processes、worker_connections)。SSL/TLS证书问题
SSL_do_handshake() failed或浏览器提示证书错误。openssl工具验证证书配置。504 Gateway Timeout
[error] upstream timed out。proxy_read_timeout、proxy_send_timeout参数值。404 Not Found
[error] open() "/path/to/resource" failed。root或alias指令,确认资源路径正确。SELinux限制
Permission denied错误,即使权限正确。setenforce 0)或添加允许规则。