1. yum 安装
1. nginx仓库添加
touch /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
2. 安装
yum install nginx -y
3. 参考
www.nginx.com/resources/w…
2. 编译安装
1. 升级 gcc
yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile
source /etc/profile
gcc --version
2. 下载 nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz -O /usr/local/src/
tar -zxf nginx-1.16.1.tar.gz
3. 安装依赖
wget https://mirrors.gigenet.com/OSDN//sfnet/p/pc/pcre/pcre/8.44/pcre-8.44.tar.gz
tar -zxf pcre-8.44.tar.gz
cd pcre-8.44
./configure
make && make install
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make && make install
wget http://www.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxf openssl-1.1.lg.tar.gz
cd openssl-1.1.lg
./Configure linux-x86_64 --prefix/usr
make && make install
4. 编译安装
cd /usr/local/src/nginx-1.16.1
./configure --prefix=/usr/local/nginx \
--with-pcre=../../pcre-8.44 \
--with-zlib=../../zlib-1.2.11 \
--with-http_ssl_module \
--with-stream
make && make install
/usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx -s quit
/usr/local/nginx/sbin/nginx -s reload
vim /etc/profile
export PATH=$PATH:/usr/local/nginx/sbin/
5. Service脚本
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-onlin.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/sh -c "/bin/kill -s HUP $(/bin/cat /usr/local/nginx/logs/nginx.pid)"
ExecStop=/bin/sh -c "/bin/kill -s TERM $(/bin/cat /var/run/nginx.pid)"
[Install]
WantedBy=multi-user.target
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl enable nginx
7. 参考
docs.nginx.com/nginx/admin…