微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CentOS7.2安装Nginx的方法步骤

CentOS7.2安装Nginx过程笔记,由于学习的需要,这段时间学一点“Nginx”。今天学习一下Nginx安装,留个笔记

查看CentOS的版本

使用一下命令来查看一下当前系统的版本

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

添加资源库

在 CentOS 系统上安装 Nginx ,你得先去添加一个资源库,像这样:

vim /etc/yum.repos.d/Nginx.repo

使用 vim 命令去打开 /etc/yum.repos.d/Nginx.repo ,如果 Nginx.repo 不存在,就会去创建一个这样的文件,打开以后按一下小 i 键,进入编辑模式,然后复制粘贴下面这几行代码,完成以后按 esc 键退出,再输入:wq (保存并退出

[Nginx]
name=Nginx repo
baseurl=http://Nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

yum 命令去安装 Nginx

完成上边操作以后,我们就可以使用 yum 命令去安装 Nginx

yum install Nginx

安装成功:

Loaded plugins: fastestmirror, langpacks
Nginx                          | 2.9 kB   00:00   
Nginx/7/x86_64/primary_db                 | 14 kB  00:01   
Loading mirror speeds from cached hostfile
 * base: mirrors.sina.cn
 * extras: mirrors.btte.net
 * updates: mirrors.sina.cn
Resolving Dependencies
--> Running transaction check
---> Package Nginx.x86_64 1:1.10.1-1.el7.ngx will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package    Arch      Version            Repository   Size
================================================================================
Installing:
 Nginx     x86_64     1:1.10.1-1.el7.ngx      Nginx     640 k

Transaction Summary
================================================================================
Install 1 Package

Total download size: 640 k
Installed size: 2.1 M
Is this ok [y/d/N]: y
Downloading packages:
Nginx-1.10.1-1.el7.ngx.x86_64.rpm             | 640 kB  00:27   
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
 Installing : 1:Nginx-1.10.1-1.el7.ngx.x86_64               1/1 
----------------------------------------------------------------------

Thanks for using Nginx!

Please find the official documentation for Nginx here:
* http://Nginx.org/en/docs/

Commercial subscriptions for Nginx are available on:
* http://Nginx.com/products/

----------------------------------------------------------------------
 Verifying : 1:Nginx-1.10.1-1.el7.ngx.x86_64               1/1 

Installed:
 Nginx.x86_64 1:1.10.1-1.el7.ngx                        

Complete!

测试Nginx配置文件

当你执行 Nginx -t 得时候,Nginx会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:

Nginx -t

打印如下:

Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful

说明配置文件成功!

centos7.0+ Nginx实现停止、启动、重启

在CentOS7中,进行chkconfig命令操作时会发现有类似“systemctl.....”的提示,systemctl可以简单实现service和chkconfig的结合,这样通过一个命令就可以实现两个命令的功能

systemctl命令的基本操作格式是:

systemctl [OPTIONS...] {COMMAND}...

Nginx服务为例,实现停止、启动、重启的动作如下:

systemctl stop  Nginx.service
systemctl start  Nginx.service
systemctl restart Nginx.service

检查服务状态

systemctl status Nginx.service

使服务开机启动

systemctl enable Nginx.service

取消服务开机启动

systemctl disable Nginx.service

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐