《走进科学》灵异事件:Nginx配置改了之后一直报错

想要安装WoWSimpleRegistration,就定下来要用nginx+php8 ,结果nginx那里加上php的支持之后一直报错:

$ sudo service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xeu nginx.service" for details.

最灵异的地方就是:将配置恢复成今天修改之前的,还是同样的报错。简直是《走进科学》IT版。

当然用sudo systemctl status nginx.service看,报错还是不一样的。

自己写php配置后的报错:

× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-02-08 07:53:31 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 47195 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 28ms

Feb 08 07:53:31 ub systemd[1]: Starting A high performance web server and a reverse proxy server...
Feb 08 07:53:31 ub nginx[47195]: nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/wow>
Feb 08 07:53:31 ub nginx[47195]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 08 07:53:31 ub systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Feb 08 07:53:31 ub systemd[1]: nginx.service: Failed with result 'exit-code'.
Feb 08 07:53:31 ub systemd[1]: Failed to start A high performance web server and a reverse proxy server.

现在恢复配置之后的报错:

× nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2024-02-08 06:33:07 UTC; 1h 9min ago
       Docs: man:nginx(8)
    Process: 29162 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 29163 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=1/FAILURE)
        CPU: 86ms

Feb 08 06:33:05 ub nginx[29163]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Feb 08 06:33:05 ub nginx[29163]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
Feb 08 06:33:06 ub nginx[29163]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Feb 08 06:33:06 ub nginx[29163]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
Feb 08 06:33:06 ub nginx[29163]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
Feb 08 06:33:06 ub nginx[29163]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
Feb 08 06:33:07 ub nginx[29163]: nginx: [emerg] still could not bind()
Feb 08 06:33:07 ub systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Feb 08 06:33:07 ub systemd[1]: nginx.service: Failed with result 'exit-code'.
Feb 08 06:33:07 ub systemd[1]: Failed to start A high performance web server and a reverse proxy server.

这样就看明白了,是80端口绑定报错。然后脑子突然在线了,是不是今天调试的时候,把apache安装上去了? 打开本地页面http://127.0.0.1 ,果然是apache的页面。原来这就是nginx恢复配置也无法启动的原因啊! 

把apache服务停掉:sudo systemctl stop apache2

然后再开nginx的服务:sudo service nginx restart

没有报错了! 好,现在开始调试php吧!

再仔细看php的报错:

skywalk@ub:/etc/nginx$ journalctl -xeu nginx.service 
Feb 08 10:30:55 ub nginx[49977]: nginx: configuration file /etc/nginx/nginx.conf test failed
Feb 08 10:30:55 ub systemd[1]: nginx.service: Control process exited, code=exited, status=1/F>
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ An ExecStartPre= process belonging to unit nginx.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 1.
Feb 08 10:30:55 ub systemd[1]: nginx.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ The unit nginx.service has entered the 'failed' state with result 'exit-code'.
Feb 08 10:30:55 ub systemd[1]: Failed to start A high performance web server and a reverse pr>
░░ Subject: A start job for unit nginx.service has failed
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit nginx.service has finished with a failure.
░░ 
░░ The job identifier is 7021 and the job result is failed.

使用nginx -t查看:

$ sudo nginx -t
nginx: [emerg] unexpected end of file, expecting ";" or "}" in /etc/nginx/conf.d/wow.conf:18
nginx: configuration file /etc/nginx/nginx.conf test failed

定位到18行 ,但是没有问题啊,括号是成对的啊,所有的语句后面都有分号。

再仔细查看,发现最后第18行,有一个“~”字符,由于它跟vi的显示字符一样(颜色不同),误以为第18行是空行,将其删除,ok拉!

现在http服务器起来了,但是php服务还没起来。 手动写index.php 文件,结果没执行,被下载下来了

怀疑是php-fpm服务没有起来,手工起,结果失败:

sudo systemctl start php-fpm
Failed to start php-fpm.service: Unit php-fpm.service not found.

先查看apt有没有安装

$ sudo apt list |grep fpm

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

libfpm-helper0/jammy 4.2-2.3 amd64
libintelrdfpmath-dev/jammy 2.0u2-4 amd64
mono-fpm-server/jammy,jammy 4.2-2.3 all
php-fpm/jammy,jammy,now 2:8.1+92ubuntu1 all [installed]
php8.1-fpm/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.14 amd64 [installed,automatic]
php8.1-fpm/jammy-updates,jammy-security 8.1.2-1ubuntu2.14 i386

再查看service

$ sudo systemctl list-units --type=service | grep php
  php8.1-fpm.service                                                                        
loaded active running The PHP 8.1 FastCGI Process Manager

启动:

$ sudo systemctl start php8.1-fpm

现在php-fpm总算启动了

php8.1-fpm.service 
             │ ├─17901 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
             │ ├─17904 php-fpm: pool www
             │ └─17905 php-fpm: pool www

发现这条语句没有: fastcgi_index  index.php;  

加上之后照旧,就像php没有起来一样。

比着这个来一下:

location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}

相关推荐

  1. nginx相关问题

    2024-02-09 06:02:04       14 阅读
  2. WordPress Nginx 502 Bad Gateway

    2024-02-09 06:02:04       79 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-09 06:02:04       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-09 06:02:04       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-09 06:02:04       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-09 06:02:04       18 阅读

热门阅读

  1. C#面:什么是Code-Behind技术

    2024-02-09 06:02:04       28 阅读
  2. PostgreSQL 与 MySQL 相比,优势何在?

    2024-02-09 06:02:04       36 阅读
  3. ASP.NET Core 7 MVC 使用 Ajax 和控制器通信

    2024-02-09 06:02:04       33 阅读
  4. C语言如何控制输出⻓度?

    2024-02-09 06:02:04       33 阅读
  5. 【flink状态管理(四)】MemoryStateBackend的实现

    2024-02-09 06:02:04       27 阅读