實驗環境centos7,ip:192.168.9.101
1、首先配置Nginx的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 <[email protected]>"
指紋 : 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.9.101進行訪問或做net映射