1.下載安裝包
wget http://nginx.org/download/nginx-1.5.9.tar.gz
直接在Linux上用命令下載
2.解壓
tar -zxvf nginx-1.5.9.tar.gz
3.設(shè)置
設(shè)置一下配置信息
./configure --prefix=/usr/local/nginx
眨补,或者不執(zhí)行此步,直接默認(rèn)配置
4.編譯及安裝
make 編譯 (make的過(guò)程是把各種語(yǔ)言寫(xiě)的源碼文件婉称,變成可執(zhí)行文件和各種庫(kù)文件)
make install 安裝 (make install是把這些編譯出來(lái)的可執(zhí)行文件和庫(kù)文件復(fù)制到合適的地方)
5.錯(cuò)誤及解決
在配置信息的時(shí)候框沟,也就是在第三步葫松,出現(xiàn)了一下錯(cuò)誤:
錯(cuò)誤為:./configure: error: the HTTP rewrite module requires the PCRE library.
安裝pcre-devel解決問(wèn)題
yum -y install pcre-devel
還有可能出現(xiàn):
錯(cuò)誤提示:./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
6.啟動(dòng)與關(guān)閉
安裝后在linux下啟動(dòng)和關(guān)閉nginx:
啟動(dòng)操作
/usr/local/nginx/sbin/nginx 啟動(dòng)
/usr/local/nginx/sbin/nginx -t 查看配置信息是否正確
netstat -ntlp 查看服務(wù)是否啟動(dòng)
停止操作
停止操作是通過(guò)向nginx進(jìn)程發(fā)送信號(hào)(什么是信號(hào)請(qǐng)參閱linux文 章)來(lái)進(jìn)行的
步驟1:查詢nginx主進(jìn)程號(hào)
ps -ef | grep nginx
在進(jìn)程列表里 面找master進(jìn)程碳竟,它的編號(hào)就是主進(jìn)程號(hào)了空另。
步驟2:發(fā)送信號(hào)
從容停止Nginx:
kill -QUIT 主進(jìn)程號(hào)
快速停止Nginx:
kill -TERM 主進(jìn)程號(hào)
強(qiáng)制停止Nginx:
pkill -9 nginx
另外, 若在nginx.conf配置了pid文件存放路徑則該文件存放的就是Nginx主進(jìn)程號(hào)腋寨,如果沒(méi)指定則放在nginx的logs目錄下聪铺。有了pid文 件,我們就不用先查詢Nginx的主進(jìn)程號(hào)精置,而直接向Nginx發(fā)送信號(hào)了计寇,命令如下:
kill -信號(hào)類型 '/usr/nginx/logs/nginx.pid'
平滑重啟
如果更改了配置就要重啟Nginx,要先關(guān)閉Nginx再打開(kāi)脂倦?不是的,可以向Nginx 發(fā)送信號(hào)元莫,平滑重啟赖阻。
平滑重啟命令:
kill -HUP 住進(jìn)稱號(hào)或進(jìn)程號(hào)文件路徑或者使用/usr/nginx/sbin/nginx -s reload 注意,修改了配置文件后最好先檢查一下修改過(guò)的配置文件是否正 確踱蠢,以免重啟后Nginx出現(xiàn)錯(cuò)誤影響服務(wù)器穩(wěn)定運(yùn)行火欧。判斷Nginx配置是否正確命令如下:
nginx -t -c /usr/nginx/conf/nginx.conf或者/usr/nginx/sbin/nginx -t 如下圖:
原文地址:
http://blog.xiaoyulive.top/2017/05/linux%E4%B8%8B%E5%AE%89%E8%A3%85nginx/
參考資料:
http://www.cnblogs.com/kunhu/p/3633002.html