安裝所需環境
1. gcc 安裝
安裝 nginx 需要先將官網下載的源碼進行編譯,編譯依賴 gcc 環境,如果沒有 gcc 環境,則需要安裝:
yum?install?gcc-c++
2. pcre pcre-devel 安裝
pcre(perl compatible regular expressions) 是一個perl庫,包括 perl 兼容的正則表達式庫。nginx 的 http 模塊使用 pcre 來解析正則表達式,所以需要在 linux 上安裝 pcre 庫,pcre-devel 是使用 pcre 開發的一個二次開發庫。nginx也需要此庫。命令:
yum?install?-y?pcre?pcre-devel
3. zlib 安裝
zlib 庫提供了很多種壓縮和解壓縮的方式, nginx 使用 zlib 對 http 包的內容進行 gzip ,所以需要在 centos 上安裝 zlib 庫。
yum?install?-y?zlib?zlib-devel
4. openssl 安裝
openssl 是一個強大的安全套接字層密碼庫,囊括主要的密碼算法、常用的密鑰和證書封裝管理功能及 ssl 協議,并提供豐富的應用程序供測試或其它目的使用。
nginx 不僅支持 http 協議,還支持 https(即在ssl協議上傳輸http),所以需要在 centos 安裝 openssl 庫。
yum?install?-y?openssl?openssl-devel
安裝
1.nginx網址
2.使用wget命令下載
#wget?-c?https://nginx.org/download/nginx-1.12.1.tar.gz
3.解壓
#tar?-zxvf?nginx-1.12.1.tar.gz #cd?nginx-1.12.1
4.配置
#./configure
5.安裝
#make
#make?install
查找安裝路徑:
#whereis?nginx
啟動、停止nginx
#cd?/usr/local/nginx/sbin/ ./nginx? ./nginx?-s?stop ./nginx?-s?quit ./nginx?-s?reload
./nginx -s quit:此方式停止步驟是待nginx進程處理任務完畢進行停止。
./nginx -s stop:此方式相當于先查出nginx進程id再使用kill命令強制殺掉進程。
查詢nginx進程:
#ps?aux|grep?nginx
啟動nginx,在瀏覽器中輸入localhost