1.配置相關環境:
yum install -y gcc glibc gcc-c++ zlib pcre-devel openssl-devel
rewrite模塊需要pcre庫
ssl功能需要openssl庫
gzip模塊需要zlib庫
2.創建nginx用戶
useradd -s /sbin/nologin -M www
-M 不創建家目錄
3.進入用戶級源碼目錄並下載nginx源碼
www.nginx.org
cd /usr/local/src wget http://nginx.org/download/nginx-1.12.0.tar.gz
4.解壓源碼包並進入nginx目錄、
tar xzvf nginx-1.12.0.tar.gz cd nginx-1.12.0/
5.執行./configure腳本檢查環境,生成安裝規則文件makefile
./configure --prefix=/usr/local/nginx-1.12.0 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
--with-http_stub_status_module 狀態模塊,用於監控nginx
6.根據makefile文件編譯安裝
make && make install
7.創建軟連接
ln -s /usr/local/nginx-1.12.0/ /usr/local/nginx
8.查看80端口是否被占用
netstat -ntlp
9.編輯配置文件/usr/local/nginx/conf/nginx.conf
vim /usr/local/nginx/conf/nginx.conf
location 用於匹配統一資源標識符(URI)
10.進行配置文件測試
/usr/local/nginx/sbin/nginx -t
11.啟動nginx
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s reload 重啟nginx