自己写的一个一键编译安装nginx的sh CentOS Linux release 7.2.1511 (Core) 下亲测有效
#!/bin/bash
echo "---------------- download nginx -------------------";
if [ ! -d "/usr/local/download" ];then
mkdir -p /usr/local/download
fi
cd /usr/local/download
wget http://nginx.org/download/nginx-1.20.0.tar.gz
tar -zxvf nginx-1.20.0.tar.gz
cd nginx-1.20.0
echo "---------------- install gcc Dev -------------------";
yum install -y gcc gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
echo "---------------- add user --------------------------";
groupadd nginx
useradd -g nginx nginx
echo "---------------- install... --------------------------";
./configure \
--prefix=/usr/local/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
make && make install
echo "---------------- nginx -v ------------------------------";
mkdir -p /var/cache/nginx
chown -R nginx:nginx /usr/local/nginx
/usr/local/nginx/sbin/nginx -v
上面sh下载链接 https://download.csdn.net/download/BookNoteY/18881146
下载的nginx版本可自由修改 如果觉得有用点个赞吧!
常用命令说明
# 重置配置文件
/usr/local/nginx -s reload
# 启动 nginx
/usr/local/nginx
# 或
/usr/local/nginx -c /配置文件路径
# 快速关闭nginx
/usr/local/nginx -s stop
# 正常关闭
/usr/local/nginx -s quit
下面是脚本一步步流程介绍
查看当前服务器 系统内核
unane -a
查看centos 版本
cat /etc/redhat-release
nginx 官网下载页
http://nginx.org/en/download.html
下载个稳定版本就ok
当前最新1.18 下载地址
http://nginx.org/download/nginx-1.18.0.tar.gz
随便建立一个目录 mkdir service
mkdir -p /usr/local/download && cd /usr/local/download
wget http://nginx.org/download/nginx-1.18.0.tar.gz
yum安装 编译文件&三方库
安装 Gcc 编译器
yum install -y gcc gcc-c++
安装正则表达式PCRE库
yum install -y pcre pcre-devel
安装 zlib压缩库
yum install -y zlib zlib-devel
安装openssl开发库
yum install -y openssl openssl-devel
解压目录 并进入目录
tar -axv -f nginx-1.18.0.tar.gz && cd nginx-1.18.0
创建 nginx 用户
groupadd nginx
useradd nginx -g nginx
生成make 文件 make参数说明(https://cloud.tencent.com/developer/article/1619507)
cd /usr/local/download/nginx-1.20.0
--prefix=/usr/local/nginx \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream \
--with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module
make && make install
'/usr/local/nginx/conf/scgi_params.default'
test -f '/usr/local/nginx/conf/nginx.conf' \
|| cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf'
cp conf/nginx.conf '/usr/local/nginx/conf/nginx.conf.default'
test -d '/var/run' \
|| mkdir -p '/var/run'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
test -d '/usr/local/nginx/html' \
|| cp -R html '/usr/local/nginx'
test -d '/var/log/nginx' \
|| mkdir -p '/var/log/nginx'
make[1]: Leaving directory `/usr/local/download/nginx-1.20.0'
如上面所示代表成功
修改nginx文件夹宿主并查看版本
chown -R nginx:nginx /usr/local/nginx
/usr/local/nginx/sbin/nginx -v