当前位置 主页 > 服务器问题 > nginx问题汇总 >

    CentOS7.2安装Nginx的方法步骤

    栏目:nginx问题汇总 时间:2019-03-08 16:26

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

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

    查看CentOS的版本

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

    [root@localhost ~]# cat /etc/redhat-releaseCentOS 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 repobaseurl=http://nginx.org/packages/centos/$releasever/$basearch/gpgcheck=0enabled=1

    yum 命令去安装 nginx

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

    yum install nginx

    安装成功:

    Loaded plugins: fastestmirror, langpacksnginx                          | 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.cnResolving Dependencies--> Running transaction check---> Package nginx.x86_64 1:1.10.1-1.el7.ngx will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package    Arch      Version            Repository   Size================================================================================Installing: nginx     x86_64     1:1.10.1-1.el7.ngx      nginx     640 kTransaction Summary================================================================================Install 1 PackageTotal download size: 640 kInstalled size: 2.1 MIs this ok [y/d/N]: yDownloading packages:nginx-1.10.1-1.el7.ngx.x86_64.rpm             | 640 kB  00:27   Running transaction checkRunning transaction testTransaction test succeededRunning 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 oknginx: configuration file /etc/nginx/nginx.conf test is successful