天天看點

linux下安裝nginx

linux系統為centos 64位

第一步:從http://nginx.org/download/上下載下傳相應的版本(或者wget http://nginx.org/download/nginx-1.5.9.tar.gz直接在linux上用指令下載下傳)

第二步:解壓 tar -zxvf nginx-1.5.9.tar.gz 

第三步:設定一下配置資訊 ./configure --prefix=/usr/local/nginx ,或者不執行此步,直接預設配置

第四步:

make 編譯 (make的過程是把各種語言寫的源碼檔案,變成可執行檔案和各種庫檔案)

make install 安裝 (make install是把這些編譯出來的可執行檔案和庫檔案複制到合适的地方)

在配置資訊的時候,也就是在第三步,出現了一下錯誤:

linux下安裝nginx

錯誤為:./configure: error: the http rewrite module requires the pcre library.

安裝pcre-devel解決問題

yum -y install pcre-devel

還有可能出現:

錯誤提示:./configure: error: the http cache module requires md5 functions

from openssl library.   you can either disable the module by using

--without-http-cache option, or install the openssl library into the system,

or build the openssl library statically from the source with nginx by using

--with-http_ssl_module --with-openssl=<path> options.

解決辦法:

yum -y install openssl openssl-devel

安裝後在linux下啟動和關閉nginx:

啟動操作

/usr/nginx/sbin/nginx (/usr/nginx/sbin/nginx -t 檢視配置資訊是否正确)

停止操作

停止操作是通過向nginx程序發送信号(什麼是信号請參閱linux文 章)來進行的

步驟1:查詢nginx主程序号

ps -ef | grep nginx

在程序清單裡 面找master程序,它的編号就是主程序号了。

步驟2:發送信号

從容停止nginx:

kill -quit 主程序号

快速停止nginx:

kill -term 主程序号

強制停止nginx:

pkill -9 nginx

另外, 若在nginx.conf配置了pid檔案存放路徑則該檔案存放的就是nginx主程序号,如果沒指定則放在nginx的logs目錄下。有了pid文 件,我們就不用先查詢nginx的主程序号,而直接向nginx發送信号了,指令如下:

kill -信号類型 '/usr/nginx/logs/nginx.pid'

平滑重新開機

如果更改了配置就要重新開機nginx,要先關閉nginx再打開?不是的,可以向nginx 發送信号,平滑重新開機。

平滑重新開機指令:

kill -hup 住進稱号或程序号檔案路徑

或者使用

/usr/nginx/sbin/nginx -s reload

注意,修改了配置檔案後最好先檢查一下修改過的配置檔案是否正 确,以免重新開機後nginx出現錯誤影響伺服器穩定運作。判斷nginx配置是否正确指令如下:

nginx -t -c /usr/nginx/conf/nginx.conf

或者

/usr/nginx/sbin/nginx -t

如下圖:

linux下安裝nginx

繼續閱讀