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 ,或者不執(zhí)行此步,直接默認配置
第四步:
make?編譯 (make的過程是把各種語言寫的源碼文件,變成可執(zhí)行文件和各種庫文件)
make install?安裝 (make install是把這些編譯出來的可執(zhí)行文件和庫文件復制到合適的地方)
在配置信息的時候,也就是在第三步,出現了一下錯誤:

錯誤為:./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進程發(fā)送信號(什么是信號請參閱linux文?章)來進行的
步驟1:查詢nginx主進程號
ps?-ef?|?grep?nginx
在進程列表里?面找master進程,它的編號就是主進程號了。
步驟2:發(fā)送信號
從容停止Nginx:
kill?-QUIT?主進程號
快速停止Nginx:
kill?-TERM?主進程號
強制停止Nginx:
pkill?-9?nginx
另外,?若在nginx.conf配置了pid文件存放路徑則該文件存放的就是Nginx主進程號,如果沒指定則放在nginx的logs目錄下。有了pid文?件,我們就不用先查詢Nginx的主進程號,而直接向Nginx發(fā)送信號了,命令如下:
kill?-信號類型?'/usr/nginx/logs/nginx.pid'
平滑重啟
如果更改了配置就要重啟Nginx,要先關閉Nginx再打開?不是的,可以向Nginx?發(fā)送信號,平滑重啟。
平滑重啟命令:
kill?-HUP?住進稱號或進程號文件路徑
或者使用
/usr/nginx/sbin/nginx?-s?reload
注意,修改了配置文件后最好先檢查一下修改過的配置文件是否正?確,以免重啟后Nginx出現錯誤影響服務器穩(wěn)定運行。判斷Nginx配置是否正確命令如下:
nginx?-t?-c?/usr/nginx/conf/nginx.conf
或者
/usr/nginx/sbin/nginx?-t
如下圖:
