服务器之家:专注于服务器技术及软件下载分享
分类导航

Linux|Centos|Ubuntu|系统进程|Fedora|注册表|Bios|Solaris|Windows7|Windows10|Windows11|windows server|

香港云服务器
服务器之家 - 服务器系统 - Centos - CentOS7.2安装Nginx的方法步骤

CentOS7.2安装Nginx的方法步骤

2022-02-10 16:36Sunsol Centos

本篇文章主要介绍了CentOS7.2安装 Nginx的方法步骤,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

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

查看CentOS的版本

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

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

添加资源库

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

?
1
vim /etc/yum.repos.d/nginx.repo

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

?
1
2
3
4
5
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1

yum 命令去安装 nginx

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

?
1
yum install nginx

安装成功:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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会去测试你得配置文件得语法,并告诉你配置文件是否写得正确,同时也告诉了你配置文件得路径:

?
1
nginx -t

打印如下:

?
1
2
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命令的基本操作格式是:

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

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

?
1
2
3
systemctl stop  nginx.service
systemctl start  nginx.service
systemctl restart nginx.service

检查服务状态

?
1
systemctl status nginx.service

使服务开机启动

?
1
systemctl enable nginx.service

取消服务开机启动

?
1
systemctl disable nginx.service

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

原文链接:http://www.jianshu.com/p/fd23af327b77?utm_source=tuicool&utm_medium=referral

延伸 · 阅读

精彩推荐
  • Centoscentos 安装与操作方法

    centos 安装与操作方法

    这篇文章主要介绍了centos 安装与操作方法,需要的朋友可以参考下...

    centos之家5272019-07-11
  • CentosCentOS 6.6实现永久修改DNS地址的方法

    CentOS 6.6实现永久修改DNS地址的方法

    这篇文章主要介绍了CentOS 6.6实现永久修改DNS地址的方法,涉及针对CentOS配置文件的相关设置技巧,具有一定参考借鉴价值,需要的朋友可以参考下 ...

    Linux社区4472020-08-21
  • CentosCentos 7开启网卡自动获取IP的详细方法

    Centos 7开启网卡自动获取IP的详细方法

    本篇文章主要介绍了Centos 7开启网卡自动获取IP的详细方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    凌锋8972021-12-29
  • CentosCentOS7设置日期和时间方法以及基本概念介绍

    CentOS7设置日期和时间方法以及基本概念介绍

    这篇文章主要介绍了CentOS7设置日期和时间方法以及基本概念介绍,本文讲解使用CentOS7中的新命令timedatectl设置日期时间方法,需要的朋友可以参考下 ...

    CentOS之家6522019-09-19
  • Centoscentos不小心删除/root目录该如何解决?

    centos不小心删除/root目录该如何解决?

    一些朋友最近在问小编centos不小心删除/root目录该如何解决?今天小编就为大家分享centos不小心删除/root目录解决办法;希望对大家会有帮助,有需要的朋友...

    脚本之家8022019-05-29
  • CentosCentOS6.5下Redis安装与配置详细步骤

    CentOS6.5下Redis安装与配置详细步骤

    本篇文章主要介绍了CentOS6.5下Redis安装与配置详细步骤,详细介绍redis单机单实例安装与配置,服务及开机自启动。有兴趣的可以了解一下。...

    飞流11452021-12-24
  • CentosCentos7运用/dev/shm进行网站优化

    Centos7运用/dev/shm进行网站优化

    这篇文章主要介绍了LINUX中Centos7运用/dev/shm进行网站优化相关知识点,对此有兴趣的朋友参考学习下。...

    彬菌9912022-03-02
  • CentosCentOS下Uptime命令详解

    CentOS下Uptime命令详解

    在Linux下,我们可以使用uptime命令,而且此命令不必使用root权限。uptime命令在系统中已经默认安装了。今天小编为大家带来的是CentOS下Uptime命令详解;希望...

    CentOS之家11482019-06-19
771