在Centos下安裝nginx

安裝


在Centos下,yum源不提供nginx的安裝,能夠經過切換yum源的方法獲取安裝。也能夠經過直接下載安裝包的方法,如下命令均需root權限執行:nginx

首先安裝必要的庫(nginx 中gzip模塊須要 zlib 庫,rewrite模塊須要 pcre 庫,ssl 功能須要openssl庫)。選定/usr/local爲安裝目錄,如下具體版本號根據實際改變。瀏覽器

1.安裝PCRE庫測試

$ cd /usr/local/
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
$ tar -zxvf pcre-8.36.tar.gz
$ cd pcre-8.36
$ ./configure
$ make
$ make install

2.安裝zlib庫.net

$ cd /usr/local/ 
$ wget http://zlib.net/zlib-1.2.8.tar.gz
$ tar -zxvf zlib-1.2.8.tar.gz
$ cd zlib-1.2.8
$ ./configure
$ make
$ make install

3.安裝sslcode

$ cd /usr/local/
$ wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
$ tar -zxvf openssl-1.0.1j.tar.gz
$ ./config
$ make
$ make install

4.安裝nginxip

$ cd /usr/local/
$ wget http://nginx.org/download/nginx-1.8.0.tar.gz
$ tar -zxvf nginx-1.8.0.tar.gz
$ cd nginx-1.8.0  
$ ./configure --prefix=/usr/local/nginx 
$ make
$ make install

在--prefix後面接如下命令:ssl

--with-pcre=/usr/local/pcre-8.36 指的是pcre-8.36 的源碼路徑。
--with-zlib=/usr/local/zlib-1.2.8 指的是zlib-1.2.8 的源碼路徑。

點擊此處下載安裝腳本get

5.啓動源碼

$ /usr/local/nginx/sbin/nginx

檢查是否啓動成功:openssl

打開瀏覽器訪問此機器的 IP,若是瀏覽器出現 Welcome to nginx! 則表示 Nginx 已經安裝並運行成功。

部分命令以下:

重啓:
$ /usr/local/nginx/sbin/nginx –s reload

中止:
$ /usr/local/nginx/sbin/nginx –s stop

測試配置文件是否正常:
$ /usr/local/nginx/sbin/nginx –t

強制關閉:
$ pkill nginx

配置


以上安裝方法nginx的配置文件位於

/usr/local/nginx/conf/nginx.conf
相關文章
相關標籤/搜索