1、添加Nginx yum repository
先参考: nginx官方安装说明
从Nginx官方可以知道, Nginx官方为Linux各发行版提供了便捷的方法安装.下面简单说下centos下安装Nginx的方法.
添加Nginx的yum仓库, 创建文件名为/etc/yum.repos.d/Nginx.repo并拷贝粘贴以下配置内容:
stables version的配置如下(最新稳定版采用)
[Nginx]
name=Nginx repo
baseurl=http://Nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
其中, 由官方信息可知变量$releasever可替换为对于的版本, 如5,6,7分别对应5.x,6.x,7.x
Due to differences between how CentOS,RHEL,and Scientific Linux populate the $releasever variable,it is necessary to manually replace $releasever with either 5 (for 5.x) or 6 (for 6.x),depending upon your OS version.
保存退出后, 执行yum makecache出现如下错误信息:
# yum makecache
2、 yum安装Nginx
# yum install Nginx
3、 检测Nginx是否安装成功
Nginx默认的配置目录为/etc/Nginx/, 配置文件为/etc/Nginx/Nginx.conf
# Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful
#
# Nginx -v
Nginx version: Nginx/1.12.0
# vim /etc/Nginx/conf.d/default.conf
常用Nginx命令
启动Nginx
# service Nginx start
停止Nginx
# service Nginx stop
重启Nginx
# service Nginx restart
启动后在浏览器输入http://127.0.0.1,如下图
至此Nginx已经可以使用了