nginx之Job for nginx.service failed because the control process exited with error code. See "systemct

启动ngnix失败:

systemctl restart nginx

报错如下: 

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

启动失败很大概率原因是配置文件有问题。
重点来了,你还可以通过这条命令去校验你的Nginx配置是否成功:

nginx -t

结果如下:

[root@fuyun /]# nginx -t
nginx: [emerg] duplicate location "/" in /etc/nginx/nginx.conf:51
nginx: configuration file /etc/nginx/nginx.conf test failed

说明配置的51行重复了

我打开ngnix.conf删掉重复项,终端输入:

vi /etc/nginx/nginx.conf

打开编辑:

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
         server_name  _;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
             root   /usr/local/nginx/html;
             index  index.php index.html index.htm;
}
        location ~*^.+$ {
            root   /root/sites/jd/;
            index  index.html index.htm;
        }
        location / {
            root   html;
            index  index.html index.htm;
        }
        #error_page  404              /404.html;
                # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           /usr/local/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
              fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }
        location ~ \.html$ {
            root           /usr/local/nginx/html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.html;
        fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

可以看的这个location重复了,

location / {
            root   html;
            index  index.html index.htm;
        }

将其删,然后再次执行nginx -t命令:

[root@fuyun /]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

这就是ok了,然后就可以重新启动nginx服务了,终端输入:

systemctl restart nginx

没有任何提示,就说明重启成功了,然后重新加载配置文件:

service nginx reload

结果:

[root@fuyun /]# service nginx reload
Reloading nginx configuration (via systemctl):             [  OK  ]
[root@fuyun /]# 

这个ok了,就可以尽情的访问了。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误是在启动nginx服务时遇到的。根据引用和引用中的信息,错误消息显示为"Job for nginx.service failed because the control process exited with error code."。这个错误通常是由于nginx服务的控制进程异常退出导致的。要了解更多详细信息,可以使用命令"systemctl status nginx.service"和"journalctl -xe"来查看。引用中提到,重新启动nginx服务后,错误消失并且查看nginx服务状态显示为successful。因此,重新启动nginx服务可能是解决这个错误的方法。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [启动nginx服务报错Job for nginx.service failed because the control process exited with error code.](https://blog.csdn.net/see__you__again/article/details/116123488)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Nginx——Nginx启动报错Job for nginx.service failed because the control process exited with error ...](https://blog.csdn.net/li1325169021/article/details/118462921)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值