linux7/centos7通过yum安装nginx

实验环境centos7,ip:192.168.11.123

1、首先配置yum源,使用vim命令新建nginx.repo文件并写入内容如下

[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
##内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

2、安装nginx

[root@localhost ~]# yum install -y nginx
已加载插件:fastestmirror
nginx-stable                                                                                         | 2.9 kB  00:00:00     
nginx-stable/7/x86_64/primary_db                                                                     |  49 kB  00:00:02     
Loading mirror speeds from cached hostfile
 * base: ftp.sjtu.edu.cn
 * extras: ftp.sjtu.edu.cn
 * updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 nginx.x86_64.1.1.16.1-1.el7.ngx 将被 安装
--> 解决依赖关系完成

依赖关系解决

============================================================================================================================
 Package                 架构                     版本                                 源                              大小
============================================================================================================================
正在安装:
 nginx                   x86_64                   1:1.16.1-1.el7.ngx                   nginx-stable                   766 k

事务概要
============================================================================================================================
安装  1 软件包

总下载量:766 k
安装大小:2.7 M
Downloading packages:
警告:/var/cache/yum/x86_64/7/nginx-stable/packages/nginx-1.16.1-1.el7.ngx.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID 7bd9bf62: NOKEY
nginx-1.16.1-1.el7.ngx.x86_64.rpm 的公钥尚未安装
nginx-1.16.1-1.el7.ngx.x86_64.rpm                                                                    | 766 kB  00:00:41     
从 https://nginx.org/keys/nginx_signing.key 检索密钥
导入 GPG key 0x7BD9BF62:
 用户ID     : "nginx signing key "
 指纹       : 573b fd6b 3d8f bc64 1079 a6ab abf5 bd82 7bd9 bf62
 来自       : https://nginx.org/keys/nginx_signing.key
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 1:nginx-1.16.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/

Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html

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

----------------------------------------------------------------------
  验证中      : 1:nginx-1.16.1-1.el7.ngx.x86_64                                                                         1/1 

已安装:
  nginx.x86_64 1:1.16.1-1.el7.ngx                                                                                           

完毕!

3、启动nginx,使用netstat -ntlp命令查看端口进程已启用

[root@localhost ~]# service nginx start
Redirecting to /bin/systemctl start nginx.service
[root@localhost ~]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1378/nginx: master  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      909/sshd            
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1156/master         
tcp6       0      0 :::22                   :::*                    LISTEN      909/sshd            
tcp6       0      0 ::1:25                  :::*                    LISTEN      1156/master   

4、临时关闭防火墙并使用网页浏览访问

[root@localhost ~]# systemctl stop firewalld.service

在同一网段的主机浏览器上输入:192.168.11.123进行访问或做net映射
linux7/centos7通过yum安装nginx_第1张图片
永久关闭防火墙命令

[root@localhost ~]# systemctl disable firewalld

关闭selinux

[root@localhost ~]# vim /etc/selinux/config

linux7/centos7通过yum安装nginx_第2张图片
vim命令在最小安装时centos7系统没有自带,安装vim命令

yum install -y vim

你可能感兴趣的:(nginx配置)