检查是否有gcc和g++命令
gcc --version
g++ --version
# 如果没有,在线安装命令:
yum install gcc
yum install gcc gcc-c++
# 离线情况找离线安装包安装。
附在线安装依赖:
yum -y install gcc pcre-devel zlib-devel openssl openssl-devel
nginx-xxx.tar.gz,下载地址
zlib-xxx.tar.gz,下载地址
pcre-xxx.tar.gz 下载地址
openssl-xxx.tar.gz 下载地址
把上述四个文件上传到 /usr/local/src
目录。
# 进入目录
cd /usr/local/src
# 解压
tar -zxvf openssl-1.0.2t.tar.gz -C /usr/local
# 进入解压目录
cd /usr/local/openssl-1.0.2t
# 配置
./config
# 编译安装(需要几分钟)
make && make install
# 进入目录
cd /usr/local/src
# 解压
tar -zxvf pcre-8.43.tar.gz -C /usr/local
# 进入解压目录
cd /usr/local/pcre-8.43
# 配置
./configure
# 编译安装
make && make install
# 进入目录
cd /usr/local/src
# 解压
tar -zxvf zlib-1.2.11.tar.gz -C /usr/local
# 进入解压目录
cd /usr/local/zlib-1.2.11
# 配置
./configure
# 编译安装
make && make install
# 创建nginx用户
useradd -s /sbin/nologin -M nginx
# 进入目录
cd /usr/local/src
# 解压
tar -zxvf nginx-1.16.1.tar.gz
# 进入解压目录
cd nginx-1.16.1
# 配置
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-pcre=/usr/local/pcre-8.43 --with-zlib=/usr/local/zlib-1.2.11 --with-openssl=/usr/local/openssl-1.0.2t
# 编译安装(需要几分钟)
make && make install
# 创建软连接
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
# nginx启动文件
[Unit]
Description=nginx
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
#User=nginx
#Group=nginx
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
# Disable service start and stop timeout logic of systemd for nginx service.
TimeoutSec=0
# Start main service
ExecStart=/usr/bin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecStop=/usr/bin/nginx -s stop
ExecReload=/usr/bin/nginx -s reload
# Sets open_files_limit
LimitNOFILE = 5000
Restart=on-failure
RestartPreventExitStatus=1
PrivateTmp=false