首先找到Nginx下載官網:http://nginx.org/en/download.html
看到內容如下:
nginx: download |
english русский 簡體中文 עברית 日本語 türkçe news about download security advisories documentation pgp keys faq links books support donation trac wiki nginx.com |
||||||||||||||||||||
Development version
Stable version
Legacy versions
Source CodeRead-only Subversion repositories:
Read-only Mercurial repositories:
Pre-Built Linux Packages for StableTo enable automatic updates of Linux packages set up the yum repository for the RHEL/CentOS distributions, or the apt repository for the Debian/Ubuntu distributions. To set up the yum repository for RHEL/CentOS, choose the corresponding This package contains yum configuration file and a public PGP key necessary to authenticate signed RPMs. Download and install it, then run the following: yum install nginx Alternatively, a repository configuration can be added manually without installing the [nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1 Replace “ |
讓我們重點關注如下描述:
Pre-Built Linux Packages for Stable
To enable automatic updates of Linux packages set up the yum repository for the RHEL/CentOS distributions, or the apt repository for the Debian/Ubuntu distributions.
To set up the yum repository for RHEL/CentOS, choose the corresponding nginx-release
package from the list:
This package contains yum configuration file and a public PGP key necessary to authenticate signed RPMs. Download and install it, then run the following:
yum install nginx
Alternatively, a repository configuration can be added manually without installing the nginx-release
package. Create the file named /etc/yum.repos.d/nginx.repo
with
the following contents:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/ gpgcheck=0 enabled=1
Replace “OS
” with “rhel
” or “centos
”, depending on the distribution used, and “OSRELEASE
” with “5
” or “6
”,
for 5.x or 6.x versions, respectively.
方式一
點擊“CentOS 6”這個鏈接下載一個rpm文件,然後安裝之
>wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
>rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm
這個rpm並非完整的nginx,而是contains yum configuration file and a public PGP key necessary to authenticate signed RPMs。意思是說這個rpm安裝完成後已經添加了響應的yum配置信息文件和對rpm進行簽名使用的公鑰。
安裝玩這個包後我們執行如下命令查看yum的respo文件:
不難發現/etc/yum.repos.d目錄下多了一個nginx.repo文件,這個文件存放的是nginx的repository 配置。這個文件之前是沒有的。查看這個文件的內容:
接下來使用如下命令真正安裝nginx:
>yum install nginx -y
方式二
手動創建一個文件/etc/yum.repos.d/nginx.repo
>touch /etc/yum.repos.d/nginx.repo
編輯文件內容爲:
[nginx] name=nginx repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=0 enabled=1
接下來使用如下命令查看可以安裝的nginx rpm資源
安裝之
查看nginx是否安裝成功
>which nginx
查看nginx幫助信息
>nginx -h
查看nginx版本
>nginx -V
啓動nginx
>nginx
通過查看端口判斷啓動是否成功
>netstat -antp|grep nginx
通過瀏覽器訪問也可以判斷是否安裝成功:
http://serverip/
出現以下內容表示成功!!!
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.Thank you for using nginx.