nginx編譯依賴gcc環境,先安裝gcc.命令:yum install gcc-c++
nginx的http模塊使用pcre來解析正則表達式,所以需要在linux上安裝pcre庫.命令:yum install -y pcre pcre-devel
nginx使用zlib對http包的內容進行gzip,所以需要在linux上安裝zlib庫.命令: yum install -y zlib zlib-devel
nginx不僅支持http協議,還支持https(即在ssl協議上傳輸http),所以需要在linux安裝openssl庫.命令: yum install -y openssl openssl-devel
2.編譯安裝
下載nginx 1.8.0,將壓縮包copy到linux服務器
解壓:
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
創建 /var/run/nginx文件夾
配置configure
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client\
--http-proxy-temp-path=/var/temp/nginx/proxy\
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi\
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi\
--http-scgi-temp-path=/var/temp/nginx/scgi
編譯安裝
make
make install
3.啓動nginx
cd /usr/local/nginx/sbin/
./nginx
4.停止nginx
cd /usr/local/nginx/sbin
./nginx -s stop
此方式是強制停止,如果有在執行的任務,會立即終止
cd /usr/local/nginx/sbin
./nginx -s quit
此方式停止步驟是待nginx進程處理任務完畢進行停止。
5.重啓nginx
./nginx -s quit
./nginx
先停止,再啓動
./nginx -s reload
重新加載配置文件
6.開啓虛擬機的80端口
因爲CentOS 7.0默認使用的是firewall作爲防火牆,我沒有改爲iptables防火牆
命令:firewall-cmd --zone=public --add-port=80/tcp --permanent
出現success表示成功
7.重啓防火牆
命令: firewall-cmd --reload
8.測試nginx服務
瀏覽器輸入虛擬機的IP地址,nginx默認是80端口,所以不用帶端口訪問,直接輸入IP就可以
OK,結束。