nginx简单报错及处理方式

预编译排错思路及案例

案例一

checking for OS

  • Linux 3.10.0-1160.el7.x86_64 x86_64
    checking for C compiler … not found

./configure: error: C compiler cc is not found

  1. 当预编译出现该报错时,表示没有C编译器,需要安装C编译器
  2. 使用yum安装即可yum install gcc gcc-c++
[root@localhost nginx-1.22.1]# ./configure --prefix=/usr/local/nginx/ --user=www --group=www --with-http_stub_status_module
checking for OS
 + Linux 3.10.0-1160.el7.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

[root@localhost nginx-1.22.1]# 
案例二
  1. 在预编译出现该报错时,表示缺少pcre,需要安装pcre
  2. 使用yum安装即可yum install pcre pcre-devel
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

[root@localhost nginx-1.22.1]# 
案例三
  1. 预编译中出现该报错时,表示缺少zlib,需要安装zlib
  2. 使用yum安装即可yum install zlib zlib-devel
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.

[root@localhost nginx-1.22.1]# 
案例四
  1. nginx安装完成后,启动时出现以下报错;原因是缺少logs目录,无法存放nginx日志
  2. 解决方法创建logs目录并授权,即可解决
[root@localhost nginx]# /usr/local/nginx/sbin/nginx
nginx: [alert] could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (2: No such file or directory)
2022/12/28 14:20:38 [emerg] 16966#0: open() "/usr/local/nginx/logs/access.log" failed (2: No such file or directory)
[root@localhost nginx]# ls
auto     CHANGES.ru        conf       contrib       html     Makefile  objs        README  scgi_temp  uwsgi_temp
CHANGES  client_body_temp  configure  fastcgi_temp  LICENSE  man       proxy_temp  sbin    src
[root@localhost nginx]# mkdir logs
[root@localhost nginx]# chmod 700 logs
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost nginx]# /usr/local/nginx/sbin/nginx
[root@localhost nginx]#

nginx测试页面无法访问

排错思路
  1. 首先进入到部署nginx的路径检查软件是否齐全,然后检查selinux是否已关闭,查看防火墙是否关闭或端口是否已放行
  2. 查看进程是否已经起来,再查看端口是否为80端口

部署dicuz论坛页面报错排查思路

案例一:页面无法访问

  1. 首先排除网络问题,打开客户端(windows、Linux)ping域名对应的IP地址
  2. 如果网络没问题,则使用telnet去测试端口
  3. 检查服务器80端口,防火墙对外开放情况
  4. 检查服务器web服务状态是否运行
#使用telnet检查域名端口,发现端口不通
[root@localhost html]# telnet discuz.sunlit.net 80
Trying 192.168.100.112...
telnet: connect to address 192.168.100.112: Connection refused
[root@localhost html]#

#查看80端口是否已经开启
[root@localhost html]# ps -ef | grep nginx
root       4401      1  0 10:52 ?        00:00:00 nginx: master process /usr/local/ngin/sbin/nginx
www       17535   4401  0 14:31 ?        00:00:00 nginx: worker process
root      17785   1571  0 17:06 pts/0    00:00:00 grep --color=auto nginx
[root@localhost html]# netstat -tnlp | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      4401/nginx: master  

#看到端口是正常开启的,则通过本机环回地址telnet端口,结果测试通
[root@localhost html]# telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

#通过本机环回地址telnet测试端口正常,表示服务征程端口却无法向外发布,检查本机防火墙
[root@localhost html]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens32
  sources: 
  services: dhcpv6-client ssh
  ports: #防火墙端口字段空白,表示没有放行任何端口
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

#添加防火墙放行80端口规则,重新加载后再查看
[root@localhost html]# firewall-cmd --add-port=80/tcp --permanent
success
[root@localhost html]# firewall-cmd --reload
success
[root@localhost html]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens32
  sources: 
  services: dhcpv6-client ssh
  ports: 80/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
	
[root@localhost html]# 

案例二:页面出现database error报错

  1. 查看是否有MySQL的进程和端口,首先确保数据库服务正常运行
  2. 如果有数据库的进程和端口存在,则检查该网页的安装时指定的域名和IP是否有指定错

请添加图片描述

案例三:迁移数据库后网站无法打开

  1. 数据迁移到新数据库后,网站无法打开
  2. 查看配置文件中的字段,看数据库配置信息是否存在有误
  3. 尝试关闭浏览器清理缓存,重新打开网站
  4. 如果清理缓存后不行,就有可能是权限问题,查看数据库用户权限
  5. 如果看到网站对接数据的用户权限已经有了,则刷新一下权限即可
#但查看到网站对接数据库的用户权限已经有了
mysql> use mysql
Database changed
mysql> select user,host,authentication_string from mysql.user where user='discuz';
+--------+------+-------------------------------------------+
| user   | host | authentication_string                     |
+--------+------+-------------------------------------------+
| discuz | %    | *7BB96B4D3E986612D96E53E62DBE9A38AAA40A5A |
+--------+------+-------------------------------------------+
1 row in set (0.00 sec)

mysql>
mysql> flush privileges;

PS:一般这种故障现象与nginx和PHP没什么关系

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值