Nginx安裝步驟:html
1、相關組件nginx
(1) Nginx自己c++
下載地址:http://nginx.org/en/download.html;提供的安裝包是Nginx-1.9.7版本。
正則表達式
(2) Rewrite模塊的正則表達式依賴庫pcre服務器
下載地址:http://www.pcre.org;提供的安裝包是pcre-8.38版本。ui
2、安裝步驟spa
(1) 安裝pcre日誌
tar -zxvf pcre-8.38.tar.gzhtm
cd pcre-8.38ip
./configure
make
make install
默認安裝到/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配置
配置文件默認在/usr/local/nginx目錄下,主要的配置文件爲conf目錄下的nginx.conf。
啓動程序文件在/usr/sbin/nginx中。
日誌在/var/log/nginx中,分別是access.log和error.log。
默認的虛擬主機的目錄設置在了/usr/share/nginx/html中。
常見配置以下:
(1) 偵聽80端口 (nginx默認監聽80端口)
listen 80;
(2) 服務器名稱
Server_name localhost;
(3) 默認主頁目錄在nginx安裝目錄的html子目錄。
root html;
index index.html index.html;
4、管理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) 查看狀態
netstat -autlp| grep nginx
(5) 檢查部署正確性
訪問http://localhost/,查看是否正常啓動。
5、常見問題
(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。