我的 NIGINX 服务器宕机了。我该如何重新启动它?我对 NGINX 和 CentOS 还很陌生

问题描述 投票:0回答:2

这是我的 NGINX 配置文件:

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        location / {
            root  /usr/share/nginx/html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

当我在我的终端输入

service nginx start
时,它显示:

Redirecting to /bin/systemctl start nginx.service
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

当我执行

systemctl status nginx.service
它显示:

systemctl status nginx.service
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Wed 2016-06-29 10:17:58 EDT; 10s ago
Process: 21459 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 21457 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 14307 (code=exited, status=0/SUCCESS)

Jun 29 10:17:58 lotto systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jun 29 10:17:58 lotto nginx[21459]: nginx: [emerg] unexpected end of file, expecting "}" in /etc/ng...f:80
Jun 29 10:17:58 lotto nginx[21459]: nginx: configuration file /etc/nginx/nginx.conf test failed
Jun 29 10:17:58 lotto systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 29 10:17:58 lotto systemd[1]: Failed to start The nginx HTTP and reverse proxy server.
Jun 29 10:17:58 lotto systemd[1]: Unit nginx.service entered failed state.
Jun 29 10:17:58 lotto systemd[1]: nginx.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

i install nginx in my remote server

但我在 nginx.conf 文件中犯了一些错误,无法恢复 所以它试图删除我的 nginx 并重新配置它 所以我使用了链接中给出的这些步骤来删除我的 nginx http://www.ehowstuff.com/how-to-remove-uninstall-nginx-on-centos-7-rhel-7-oracle-linux-7/
then i use
yum remove nginx and again reinstall it

但是当我尝试
sudo systemctl start nginx or [root@lotto nginx]# service nginx start

它的显示

nginx.service 的作业失败,因为此处的控制进程退出代码带有错误代码。有关详细信息,请参阅“systemctl status nginx.service”和“journalctl -xe”。

when i am using 
[root@lotto nginx]# systemctl status nginx.service 
showing


nginx.service - nginx HTTP 和反向代理服务器 已加载:已加载(/usr/lib/systemd/system/nginx.service;已启用;供应商预设:已禁用) 活动:自美国东部时间周五 2016-07-01 07:48:44 以来失败(结果:退出代码); 18 秒前进程:30832 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) 进程:30830 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) 主 PID:14307(代码=退出,状态=0/成功)

7 月 01 日 07:48:44 lotto systemd[1]:启动 nginx HTTP 和反向代理服务器... 7 月 01 日 07:48:44 lotto nginx[30832]:nginx:[emerg] getpwnam(“nginx”)失败在 /etc/nginx/nginx.conf:5 Jul 01 07:48:44 lotto nginx[30832]: nginx: 配置文件 /etc/nginx/nginx.conf 测试失败 Jul 01 07:48:44 lotto systemd[1]: nginx.service: 控制进程退出,代码=退出状态=1 Jul 01 07:48:44 lotto systemd[1]:无法启动 nginx HTTP 和反向代理服务器。 Jul 01 07:48:44 lotto systemd[1]:单元 nginx.service 进入失败状态。 7 月 1 日 07:48:44 lotto systemd[1]:nginx.service 失败。 和 [root@lotto nginx]# journalctl -xe

nginx.service - nginx HTTP 和反向代理服务器 已加载:已加载(/usr/lib/systemd/system/nginx.service;已启用;供应商预设:已禁用) 活动:自美国东部时间周五 2016-07-01 07:48:44 以来失败(结果:退出代码); 18 秒前 进程:30832 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE) 进程:30830 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS) 主 PID:14307(代码=退出,状态=0/成功)

nginx centos
2个回答
0
投票

错误在您的配置文件中。我在编辑你的帖子时不小心更正了它,因为我认为你复制的不正确。

这一行

Jun 29 10:17:58 lotto nginx[21459]: nginx: [emerg] unexpected end of file, expecting "}" in /etc/ng...f:80
告诉你什么时候错了。如果语法不正确,服务将不会启动。

}
文件的末尾添加一个
nginx.conf
,它应该可以工作。


0
投票

当你启动 nginx 服务有问题时,重新检查 conf 文件。 您可以使用这个检查配置错误

nginx -t -c /etc/nginx/nginx.conf
© www.soinside.com 2019 - 2024. All rights reserved.