CentOS 7 yum安裝nginx-1.12.0

CentOS 7 中的 yum 沒法直接使用 yum install nginx 這個指令去安裝nginx,因爲nginx這個服務不是yum庫中自帶的。圖1是官方提供的大致安裝步驟,圖2是官網提供的多個版本的nginx安裝包,下面是我給合自己的系統環境總結的安裝方法,供大家參考:


圖1


圖2

1、按圖1中的要求vi nginx.repo這個文件,將圖中[nginx]字段中的內容複製進去,保存退出!
[root@lnboxue ~]# vi  /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/x86_64/
gpgcheck=0
enabled=1
這裏需要注意的是:要將$releasever替換爲7,將$basearch替換成x86_64。可以通過下面這條指令獲取你自己系統的$releasever和$basearch。
[root@lnboxue ~]# rpm -qa | grep centos-release
centos-release-7-3.1611.el7.centos.x86_64


2、yum安裝nginx,參見圖3和圖4。
[root@lnboxue ~]# yum install nginx


圖3


圖4

3、可以使用兩種方法啓動nginx服務
[root@lnboxue ~]# service nginx start

[root@lnboxue ~]# systemctl start nginx


4、查看nginx服務是否已經啓動
[root@lnboxue ~]# netstat -ntl


圖5

5、查看nginx版本

[root@lnboxue ~]# nginx -v

nginx version: nginx/1.12.0


6、本地測試nginx服務
[root@lnboxue ~]# curl -i localhost
HTTP/1.1 200 OK
Server: nginx/1.12.0
Date: Tue, 04 Jul 2017 05:27:07 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 12 Apr 2017 15:23:46 GMT
…………
…………
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>

</html>


看到以上信息,說明你的nginx服務已安裝成功!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章