CentOS 7安装nginx

1. 下载对应当前系统版本的nginx包(package)

# wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2. 建立nginx的yum仓库

# rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

3.下载并安装nginx

# yum install nginx

4.启动nginx服务

# systemctl start nginx

==开启服务报错==

Starting nginx (via systemctl): Job for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.

出现这样的提示,一般先执行 $ systemctl status nginx.service 看看下面的具体情况,比如:

[root@Leco init.d]# systemctl status nginx.service
nginx.service - LSB: start and stop nginx
   Loaded: loaded (/etc/rc.d/init.d/nginx)
   Active: failed (Result: resources) since 三 2015-06-24 20:21:31 CST; 5min ago
  Process: 18620 ExecStart=/etc/rc.d/init.d/nginx start (code=exited, status=0/SUCCESS)

624 20:21:31 Leco.lan systemd[1]: Starting LSB: start and stop nginx...
624 20:21:31 Leco.lan nginx[18620]: Starting nginx: nginx: [emerg] open() "/var/run/nginx/nginx.pid" failed (2: No such file or directory)
624 20:21:31 Leco.lan nginx[18620]: [  确定  ]
624 20:21:31 Leco.lan systemd[1]: PID file /var/run/nginx/nginx.pid not readable (yet?) after start.
624 20:21:31 Leco.lan systemd[1]: Failed to start LSB: start and stop nginx.
624 20:21:31 Leco.lan systemd[1]: Unit nginx.service entered failed state.

其实看到这个systemctl这个东西出来了,就可以使用新RHEL7的启动服务方式了, 给个传送门供大家参考下这个方式:http://my.oschina.net/liucao/blog/470458

==解决方案==

sudo systemctl enable nginx.service
就会在/etc/systemd/system/multi-user.target.wants/目录下新建一个/usr/lib/systemd/system/nginx.service 文件的链接。

之后就可以使用平常的方式操作nginx

#启动服务
$ sudo systemctl start nginx.service

#查看日志
$ sudo journalctl -f -u nginx.service
-- Logs begin at 四 2015-06-25 17:32:20 CST. --
625 10:28:24 Leco.lan systemd[1]: Starting nginx - high performance web server...
625 10:28:24 Leco.lan nginx[7976]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
625 10:28:24 Leco.lan nginx[7976]: nginx: configuration file /etc/nginx/nginx.conf test is successful
625 10:28:24 Leco.lan systemd[1]: Started nginx - high performance web server.

#重启
$ sudo systemctl restart nginx.service

#重载
$ sudo systemctl reload nginx.service

#停止
$ sudo systemctl stop nginx.service

5.配置

默认的配置文件在 /etc/nginx 路径下,使用该配置已经可以正确地运行nginx;如需要自定义,修改其下的 nginx.conf 等文件即可。

6.测试

在浏览器地址栏中输入部署nginx环境的机器的IP,如果一切正常,应该能看到如下字样的内容。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值