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