Make Nginx#
Create a file named nginx.sh and save the following script content in it.
Offline installation package#
#!/bin/bash# author : Jalright
# modify the version variable ,there you need !nginx_version="1.28.0"openssl_version="3.0.12"zlib_version="1.3.1"pcre_version="8.45"
# the default install path , you can change it hereinstall_path="/usr/local/nginx"
# check file if exists , if not exit script.function checkFile() { if [ ! -f "$1" ]; then echo "$1 is not exitst" exit 1 fi}
# install complie toolsyum -y install gcc gcc-c++ make wget tar
# temp dirmkdir -p /tmp/make_nginx
cd /tmp/make_nginx
# download nginxwget -c -t 0 -T 1200 http://nginx.org/download/nginx-${nginx_version}.tar.gzcheckFile nginx-${nginx_version}.tar.gz
# download opensslwget -c -t 0 -T 1200 https://www.openssl.org/source/openssl-${openssl_version}.tar.gzcheckFile openssl-${openssl_version}.tar.gz
# download zlib for gizpwget -c -t 0 -T 1200 http://zlib.net/zlib-${zlib_version}.tar.gzcheckFile zlib-${zlib_version}.tar.gz
# download pcre for regular expressionif [ ! -f "pcre-${pcre_version}.tar.gz" ]; then wget -c -t 0 -T 1200 https://sourceforge.net/projects/pcre/files/pcre/${pcre_version}/pcre-${pcre_version}.tar.gz/download -O pcre-${pcre_version}.tar.gzficheckFile pcre-${pcre_version}.tar.gz
# Don't need install the dependent packages , we juse need source code .# When we compile nginx , it will compile with other dependent source code auto.tar zxf openssl-${openssl_version}.tar.gz || echo "unpack openssl fail" && exit 1
tar zxf zlib-${zlib_version}.tar.gz
tar zxf pcre-${pcre_version}.tar.gz
tar zxf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
# default compile with http2 module 、ssl、status ... If you need other module , you can modify it here../configure --prefix=${install_path} --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module --with-openssl=../openssl-${openssl_version} --with-pcre=../pcre-${pcre_version} --with-zlib=../zlib-${zlib_version} && exit 1
make
make install
# crete work useruseradd -M -s /sbin/nologin www
# /usr/local/nginx/sbin/nginx -VThere are even simpler ways.#
- Install using the yum tool.
#!/bin/bash# author : Olsond
# modify the version variable ,there you need !nginx_version="1.28.0"
# the default install path , you can change it hereinstall_path="/usr/local/nginx"
# check file if exists , if not exit script.function checkFile() { if [ ! -f "$1" ]; then echo "$1 is not exitst" exit 1 fi}
# install complie toolsyum -y install gcc gcc-c++ make wget tar pcre pcre-devel zlib zlib-devel openssl openssl-devel
# temp dirmkdir -p /tmp/make_nginx
cd /tmp/make_nginx
# download nginxwget -c -t 0 -T 1200 http://nginx.org/download/nginx-${nginx_version}.tar.gzcheckFile nginx-${nginx_version}.tar.gz
tar zxf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
mkdir -p /var/log/nginx /usr/local/nginx/logs# default compile with http2 module 、ssl、status ... If you need other module , you can modify it here../configure --prefix=${install_path} --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-stream --with-http_stub_status_module --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgimake && make install
# crete work useruseradd -M -s /sbin/nologin nginx
/usr/local/nginx/sbin/nginx -V
# run nginxcd /usr/local/nginx/sbin./nginx -c /usr/local/nginx/configig/nginx.confExecuted using symbolic link method.#
ln -fs /usr/local/nginx/sbin/nginx /usr/bin/nginx
nginx -v