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是把這些編譯出來的可執行檔和庫檔案複製到合適的地方)
在配置資訊的時候,也就是在第三步,出現了一下錯誤:
錯誤為:./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= 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,包括了方面的內容,希望對PHP教程有興趣的朋友有所協助。