- CentOS7.4
#!/bin/bash
yum -y install pcre pcre-devel openssl openssl-devel gcc gcc-c++ wget
wget http://nginx.org/download/nginx-1.8.1.tar.gz
tar -xzf nginx-1.8.1.tar.gz -C /usr/src/ && cd /usr/src/nginx-1.8.1
useradd -s /sbin/nologin www
./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
make && make install
#測試配置
/usr/local/nginx/sbin/nginx -t
firewall-cmd --add-port=80/tcp --permanent
firewall--cmd --reload
#啟動(dòng)主程序
/usr/local/nginx/sbin/nginx
ps -ef | grep nginx
echo "nginx instlled"
- Ubuntu18.04
apt update
#安裝依賴:gcc、g++依賴庫
apt install build-essential libtool
#安裝 pcre依賴庫(http://www.pcre.org/)
apt install libpcre3 libpcre3-dev
#安裝 zlib依賴庫(http://www.zlib.net)
apt install zlib1g-dev
apt install openssl
wget http://nginx.org/download/nginx-1.16.0.tar.gz
cd nginx-1.16.0
./configure --prefix=/usr/local/nginx
make && make install
編寫Nginx的systemd啟動(dòng)腳本,將腳本放在/lib/systemd/system/目錄下
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs
#After參數(shù)設(shè)置項(xiàng)用來確認(rèn)啟動(dòng)的順序
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
#ExecStartPre參數(shù)可確保ExecStart參數(shù)啟動(dòng)之前執(zhí)行的命令个从,這里是在啟動(dòng)之前進(jìn)行配置文件正確性的檢測
ExecStartPre=/usr/local/nginx/sbin/nginx -t
#ExecStart參數(shù)用來啟動(dòng)Nginx服務(wù)
ExecStart=/usr/local/nginx/sbin/nginx
#ExecReload參數(shù)指定重新加載時(shí)執(zhí)行的命令
ExecReload=/bin/kill -s HUP $MAINPID
#ExecStop參數(shù)指定停止Nginx服務(wù)時(shí)執(zhí)行的命令
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=True
[Install]
WantedBy=multi-user.target