AWS EC2示例重启后未启动nginx服务

vsnjm48y  于 2023-05-06  发布在  Nginx
关注(0)|答案(2)|浏览(345)

我有一个在AWS EC2上运行的Laravel应用程序。我遇到了upload_max_filesize的问题,想将其从默认的2 M增加到6 M。根据php_info(),正在使用的php.ini文件是/etc/php/8.1/fpm/php.ini,我在这个文件中更改了upload_max_filesize的值,并重新启动了nginx服务(不确定这是否足够),但它没有解决这个问题。\etc中的grep命令(grep -r“upload_max_filesize”.)显示,还有两个文件具有“upload_max_filesize”参数:/etc/php/8.1/apache2/php.ini/etc/php/8.1/cli/php.ini,我也更新了这些文件中upload_max_filesize的值,并重新启动了nginx服务。虽然ini_get()在php artisan tinker中给了我更新的值,但我的应用程序中的php_info()仍然显示2 M。所以我决定重启服务器。
然而,重启后,我的网站拒绝连接:该网站无法访问silkweb.ca拒绝连接
在检查nginx服务状态时,它看起来没有运行,尽管nginx配置是OK的

ubuntu@ip-172-31-4-36:~$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

ubuntu@ip-172-31-4-36:~$ sudo systemctl status nginx
× 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 Mon 2023-05-01 17:41:17 UTC; 24min ago
   Docs: man:nginx(8)
    CPU: 63ms

May 01 17:41:15 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
May 01 17:41:15 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
May 01 17:41:16 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
May 01 17:41:16 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
May 01 17:41:16 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
May 01 17:41:16 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)
May 01 17:41:17 ip-172-31-4-36 nginx[522]: nginx: [emerg] still could not bind()
May 01 17:41:17 ip-172-31-4-36 systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
May 01 17:41:17 ip-172-31-4-36 systemd[1]: nginx.service: Failed with result 'exit-code'.
May 01 17:41:17 ip-172-31-4-36 systemd[1]: Failed to start A high performance web server and a reverse proxy server.
ubuntu@ip-172-31-4-36:~$

为什么nginx不能启动?(我已经重新启动了服务器几次,但没有运气-在“upload_max_filesize”更改和重新启动之前,一切都工作正常。)

dhxwm5r4

dhxwm5r41#

对于将来提到这一点的任何人(见评论):

May 01 17:41:15 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Unknown error)
May 01 17:41:15 ip-172-31-4-36 nginx[522]: nginx: [emerg] bind() to [::]:80 failed (98: Unknown error)

上面的代码表明,有一个服务或进程已经在端口80上侦听,导致nginx无法绑定该端口。看起来这是由Apache被启用并首先绑定此端口引起的。禁用apache服务(或任何其他干扰的服务)将是必要的方法。

2ledvvac

2ledvvac2#

正如@Rolo787所提到的,nginx服务无法启动,因为另一个服务(apache)正在运行,该服务使用nginx所需的相同端口。检查Apache服务是否正在运行:

sudo systemctl status apache2

为了解决这个问题,我停止了Apache服务并启动了nginx:

sudo systemctl stop apache2
sudo systemctl start nginx

要禁用apache服务在重新引导时的自动启动,请使用以下命令

sudo systemctl disable apache2

运行此命令后,可以使用以下命令检查Apache服务的状态,以确保其已禁用:

sudo systemctl is-enabled apache2

相关问题