CentOS上 安裝Nginx

首先找到Nginx下載官網:http://nginx.org/en/download.html

看到內容如下:

nginx

nginx: download


english
русский

簡體中文
עברית
日本語
türkçe

news
about
download
security advisories
documentation
pgp keys
faq
links
books
support
donation

trac
wiki
twitter
nginx.com

Development version

CHANGES nginx-1.3.13  pgp nginx/Windows-1.3.13  pgp

Stable version

CHANGES-1.2 nginx-1.2.7  pgp nginx/Windows-1.2.7  pgp

Legacy versions

CHANGES-1.0 nginx-1.0.15  pgp nginx/Windows-1.0.15  pgp
CHANGES-0.8 nginx-0.8.55  pgp nginx/Windows-0.8.55  pgp
CHANGES-0.7 nginx-0.7.69  pgp nginx/Windows-0.7.69  pgp
CHANGES-0.6 nginx-0.6.39  pgp  
CHANGES-0.5 nginx-0.5.38  pgp  

Source Code

Read-only Subversion repositories:

  • code: svn://svn.nginx.org/nginx

Read-only Mercurial repositories:

  • site: http://hg.nginx.org/nginx.org

Trac source browser

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.


讓我們重點關注如下描述:

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.




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章