首页 文章

Nginx不在CentOS工作?

提问于
浏览
0
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.

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

1 回答

  • 0

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

    sudo netstat -tulpn

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

    sudo kill -2 <PID>
    sudo service nginx restart

    在我的情况下,apache httpd在同一个端口上运行,我不想杀死该进程,因此我将nginx的默认端口更改为其他端口 . 这就是我的 nginx.conf 现在的样子 .

    server {
        listen       3000 default_server;
        listen       [::]:3000 default_server;
        server_name  _;
        root         /usr/share/nginx/html;
    
        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
    
        location / {
        }
    
        error_page 404 /404.html;
            location = /40x.html {
        }
    
        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
    

    此外,请确保在此文件中, user 设置为您登录的用户(对于ex root ) .

    如果不是这种情况,您可以尝试提及的其他选项here.

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

相关问题