CentOS 7 yum安裝nginx
阿新 • • 發佈:2018-10-31
CentOS 7 中的 yum 沒法直接使用 yum install nginx 這個指令去安裝nginx,因為nginx這個服務不是yum庫中自帶的。圖1是官方提供的大致安裝步驟,圖2是官網提供的多個版本的nginx安裝包,下面是我給合自己的系統環境總結的安裝方法,供大家參考:
1、按圖1中的要求vi nginx.repo這個檔案,將圖中[nginx]欄位中的內容複製進去,儲存退出!
[[email protected] ~]# 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。
[ [email protected] ~]# rpm -qa | grep centos-release
centos-release-7-3.1611.el7.centos.x86_64
2、yum安裝nginx,參見圖3和圖4。
[[email protected] ~]# yum install nginx
3、可以使用兩種方法啟動nginx服務
[[email protected] ~]# service nginx start
或
[[email protected] ~]# systemctl start nginx
4、檢視nginx服務是否已經啟動
[[email protected] ~]# netstat -ntl
5、檢視nginx版本
[[email protected] ~]# nginx -v
nginx version: nginx/1.12.0
6、本地測試nginx服務
[[email protected] ~]# 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>