一、准備工作
1、首先我的centos7,安裝是CentOS-7-x86_64-Everything-1611的版本,
2、把系統的鏡像文件,找到packages文件下,找到
pcre-devel-8.32-15.el7_2.1.x86_64.rpm,zlib-1.2.7-17.el7.x86_64.rpm,zlib-devel-1.2.7-17.el7.x86_64.rpm,把這個三個文件解壓出來,
3、下載nginx-1.16.0.tar.gz
資源下載地址:
https://download.csdn.net/download/qijianglin/11170479
二、安裝
首先安裝插件
這個版本的centos7,安裝nginx,就是少了上面准備工作中的第二步的三個文件。所以要安裝一下:
前提把pcre-devel-8.32-15.el7_2.1.x86_64.rpm,拷貝到handgo下
chmod 755 pcre-devel-8.32-15.el7_2.1.x86_64.rpm
rpm -Uvh pcre-devel-8.32-15.el7_2.1.x86_64.rpm nodeps force
前提把zlib-1.2.7-17.el7.x86_64.rpm,zlib-devel-1.2.7-17.el7.x86_64.rpm,拷貝到handgo下
chmod 755 zlib-1.2.7-17.el7.x86_64.rpm
chmod 755 zlib-devel-1.2.7-17.el7.x86_64.rpm
rpm -Uvh zlib-1.2.7-17.el7.x86_64.rpm
rpm -Uvh zlib-devel-1.2.7-17.el7.x86_64.rpm
--建立目錄
mkdir /opt/handgo/nginx
授權
chmod 755 /opt/handgo/nginx-1.16.0.tar.gz
解壓
tar -zxvf /opt/handgo/nginx-1.16.0.tar.gz -C /opt/handgo/nginx
cd nginx/
cd nginx-1.16.0/
檢查安裝環境,是否符合
./configure
編譯安裝
make
make install
whereis nginx
啟動nginx,要先進入安裝目錄中
cd /usr/local/nginx/sbin/
啟動nginx
./nginx
查詢nginx進程:
ps aux|grep nginx
打開防火牆的80端口:
firewall-cmd zone=public add-port=80/tcp permanent
firewall-cmd reload
三、配置nginx開機啟動
1、切換到/lib/systemd/system/目錄,創建nginx.service文件vim nginx.service
我是直接用xftp,在這個目錄下創建一個叫nginx.service的文件,然後,複制的本地window下,把下面的內容拷貝進去。
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
完成後,拷貝回centos7的原來位置,
2、執行systemctl enable nginx.service使nginx開機啟動
測試是否,先進
cd /usr/local/nginx/sbin/
./nginx -s quit
啟動nginx
systemctl start nginx.service
結束nginx
systemctl stop nginx.service
重啟nginx
systemctl restart nginx.service
完成,老鐵們,沒問題。