Nginx不在CentOS中工作?

Nginx不在CentOS中工作?,nginx,centos7,Nginx,Centos7,错误:活动:自2018-04-09周一16:35:28 IST以来失败(结果:退出代码); 进程:22654 ExecStart=/usr/sbin/nginx(代码=退出,状态=1/失败) Apr 09 16:35:28 localhost.localdomain systemd[1]:无法启动nginx HTTP和反向代理服务器 该错误基本上意味着其他应用程序正在使用这些默认端口。您可以使用以下方法检查: sudo netstat-tulpn 获取已经使用该端口的进程的PID,并使用kill

错误:活动:自2018-04-09周一16:35:28 IST以来失败(结果:退出代码); 进程:22654 ExecStart=/usr/sbin/nginx(代码=退出,状态=1/失败) Apr 09 16:35:28 localhost.localdomain systemd[1]:无法启动nginx HTTP和反向代理服务器


该错误基本上意味着其他应用程序正在使用这些默认端口。您可以使用以下方法检查:

sudo netstat-tulpn

获取已经使用该端口的进程的PID,并使用kill命令发送信号

sudo kill-2

sudo服务nginx重启

在我的例子中,apachehttpd运行在同一个端口上,我不想终止该进程,所以我将nginx的默认端口更改为其他端口。这就是我的
nginx.conf
现在的样子

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost bin]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@localhost bin]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: **failed** (Result: exit-code) since Mon 2018-04-09 16:35:28 IST; 6min ago
  Process: 22654 ExecStart=/usr/sbin/nginx (**code=exited, status=1/FAILURE**)
  Process: 22597 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 22595 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Apr 09 16:35:27 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Apr 09 16:35:27 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] still could not bind()
Apr 09 16:35:28 localhost.localdomain systemd[1]: **Failed to start The nginx HTTP and reverse proxy server.**
Apr 09 16:35:28 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Apr 09 16:35:28 localhost.localdomain systemd[1]: nginx.service failed.
此外,请确保在此文件中,
user
设置为您登录的用户(对于ex
root

如果不是这样,您可以尝试上述其他选项


您可以使用
nginx-t
测试文件
nginx.conf
的语法是否正确。

该错误基本上意味着其他应用程序正在使用这些默认端口。您可以使用以下方法检查:

sudo netstat-tulpn

获取已经使用该端口的进程的PID,并使用kill命令发送信号

sudo kill-2

sudo服务nginx重启

在我的例子中,apachehttpd运行在同一个端口上,我不想终止该进程,所以我将nginx的默认端口更改为其他端口。这就是我的
nginx.conf
现在的样子

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost bin]# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
[root@localhost bin]# systemctl status nginx.service
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: **failed** (Result: exit-code) since Mon 2018-04-09 16:35:28 IST; 6min ago
  Process: 22654 ExecStart=/usr/sbin/nginx (**code=exited, status=1/FAILURE**)
  Process: 22597 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 22595 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Apr 09 16:35:27 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Apr 09 16:35:27 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to 0.0.0.0:443 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] bind() to [::]:80 failed (98: Address already in use)
Apr 09 16:35:28 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
Apr 09 16:35:28 localhost.localdomain nginx[22654]: nginx: [emerg] still could not bind()
Apr 09 16:35:28 localhost.localdomain systemd[1]: **Failed to start The nginx HTTP and reverse proxy server.**
Apr 09 16:35:28 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
Apr 09 16:35:28 localhost.localdomain systemd[1]: nginx.service failed.
此外,请确保在此文件中,
user
设置为您登录的用户(对于ex
root

如果不是这样,您可以尝试上述其他选项


您可以使用
nginx-t
测试文件
nginx.conf
的语法是否正确。

bind()到0.0.0.0:80失败(98:地址已在使用)
表示另一个进程(另一个
nginx
实例或另一个程序)已经在使用端口80
sudonetstat-tupln
告诉您是哪一个。这不是编程问题。您应该在适当的位置(例如,superuser.com或serverfault.com)询问此类问题。
bind()到0.0.0.0:80失败(98:地址已在使用)
表示另一个进程(另一个
nginx
实例或另一个程序)已经在使用端口80
sudonetstat-tupln
告诉您是哪一个。这不是编程问题。您应该在适当的地方(例如,superuser.com或serverfault.com)询问此类问题。