本篇文章是针对新手来写的,安装之前请先移步至 将Centos的yum源更换为国内的阿里云源 ,因为 Centos 内置的 yum 里面没有 nginx 的包,然后在网上找的其他办法又相当的繁琐,将 yum 源换成阿里的之后就没那么多的事儿了,这个是我目前找到的最快的方法了

下面的操作步骤的前提是你已经,将源换成了阿里的了
  1. 安装 nginx ``` yum install -y nginx
  1. 2. 启动 nginx
  2. - 我在这个启动的地方报了一个错误,找了好多的论坛最后在国外的一家里面发现了一样的错误,然后跟着下面网友们的回复我也试了下最后成功了,因为英文的看不懂用的是谷歌浏览器右键的翻译功能,发现翻译的挺好的
  3. > 论坛地址:[centos7 - Job for nginx.service failed because the control process exited with error code - Stack Overflow](https://stackoverflow.com/questions/44364890/job-for-nginx-service-failed-because-the-control-process-exited-with-error-code)
  4. - 常用的一些命令

//删除 ngnix 包 yum remove -y nginx //安装 ngnix 包 yum install -y nginx //查看所有正在运行的程序 ls -lart /var/run/ //查看与 nginx 相关的进程 ps -eaf |grep nginx //nginx 重新启动 systemctl restart nginx //nginx 启动 systemctl start nginx //nginx 停止 systemctl stop nginx //nginx 状态 systemctl status nginx //查看版本 nginx -v //查询文件路径有 nginx 的所有文件 rpm -ql nginx

  1. - 问题阐述
  2. 1. 我在安装之后,执行了启动的命令 `systemctl start nginx` ,然后就报了下面的错误,之后在网上查了好久都没查到原因,刚开始以为是安装包或者是源的问题,然后试了几种安装方法都报这个错误,期间已经是将源换为阿里的了还是会报错
  3. > 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

  1. > ![image.png](http://upload-images.jianshu.io/upload_images/9064013-ebec33094203f7ea.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

//进入到 ngnix 安装目录下 cd /etc/nginx //执行 nginx 命令启动 也是下面的输出,查看状态如上图 nginx

  1. > ![image.png](http://upload-images.jianshu.io/upload_images/9064013-4776913a8498201c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
  2. 2. 后来就在那个论坛里发现一哥们也遇到了这个问题,但是他的一直没解决 /摊手,最后经过千辛万苦才找到了上面说的外国论坛上的帖子,具体操作如下

//查看正在执行的与 ngnix 相关的程序 ps -eaf |grep nginx //在上面查询中找到了两个程序然后我依次将他们都杀掉,这里需要将除了最后的查询程序之外的其他程序都要杀掉 才可以 kill -9 1359 kill -9 1360 //之后我再次运行 ngnix 这次没有报错 systemctl start ngnix //查看nginx 状态 发现已经是 running 了 systemctl status nginx

```

image.png