重慶分公司,新征程啟航
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
為企業(yè)提供網(wǎng)站建設(shè)、域名注冊、服務(wù)器等服務(wù)
Nginx安裝步驟:
一、相關(guān)組件
(1) Nginx本身
下載地址:http://nginx.org/en/download.html;提供的安裝包是Nginx-1.9.7版本。
(2) Rewrite模塊的正則表達(dá)式依賴庫pcre
下載地址:http://www.pcre.org;提供的安裝包是pcre-8.38版本。
二、安裝步驟
(1) 安裝pcre
tar -zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure
make
make install
默認(rèn)安裝到/usr/local/lib下即可;安裝完成后可以#ls -l /usr/local/lib/libpcre.so
(2) 安裝nginx
tar –zxvf nginx-1.9.7.tar.gz
cd nginx-1.9.7
./configure
make
make install
三、nginx配置
配置文件默認(rèn)在/usr/local/nginx目錄下,主要的配置文件為conf目錄下的nginx.conf。
啟動程序文件在/usr/sbin/nginx中。
日志在/var/log/nginx中,分別是access.log和error.log。
默認(rèn)的虛擬主機的目錄設(shè)置在了/usr/share/nginx/html中。
常見配置如下:
(1) 偵聽80端口 (nginx默認(rèn)監(jiān)聽80端口)
listen 80;
(2) 服務(wù)器名稱
Server_name localhost;
(3) 默認(rèn)主頁目錄在nginx安裝目錄的html子目錄。
root html;
index index.html index.html;
四、管理nginx
(1) 啟動
/usr/local/nginx/sbin/nginx (/usr/nginx/sbin/nginx -t 查看配置信息是否正確)
(2) 停止
/usr/local/nginx/sbin/nginx -s stop
(3) 重啟
/usr/local/nginx/sbin/nginx-s reload
(4) 查看狀態(tài)
netstat -autlp| grep nginx
(5) 檢查部署正確性
訪問http://localhost/,查看是否正常啟動。
五、常見問題
(1) 缺少pcre庫:./configure: error: the HTTP rewrite module requires the PCRE library.
解決方法:安裝pcre。
(2) 缺少openssl:./configure: error: the HTTP cache module requires md5 functions from OpenSSL library.
解決方法:安裝openssl-devel。
(3) 缺少gcc-c++和libtool:The program \'libtool\' is currently not installed. You can install it by typing:sudo apt-get install libtool
解決方法:安裝libtool和gcc-c++。
(4) 缺少zlib:./configure: error: the HTTP gzip module requires the zlib library.
解決方法:安裝zlib。