Entirely based on Angristan's work : https://github.com/angristan/nginx-autoinstall
It's quick, possibly dirty.
Tested and validated on CentOS Linux release 7.7.1908
.
wget https://raw.githubusercontent.com/ab-a/nginx-autoinstall-centos/master/nginx-autoinstall.sh
chmod +x nginx-autoinstall.sh
./nginx-autoinstall.sh
[root@node-000 nginx-autoinstall-centos]# diff ../nginx-autoinstall/nginx-autoinstall.sh nginx-autoinstall.sh
139a140,142
> # Create nginx user
> id -u nginx &>/dev/null || useradd -s /bin/false nginx
>
146,147c149,150
< apt-get update
< apt-get install -y build-essential ca-certificates wget curl libpcre3 libpcre3-dev autoconf unzip automake libtool tar git libssl-dev zlib1g-dev uuid-dev lsb-release libxml2-dev libxslt1-dev
---
> yum update
> yum install -y gcc gcc-c++ make ca-certificates wget curl autoconf unzip automake libtool tar git zlib-devel uuid-devel libxml2-devel libxslt-devel uuid-devel openssl-devel pcre pcre-devel libuuid-devel libmaxminddb-devel
363,368c366,367
< # Block Nginx from being installed via APT
< if [[ $(lsb_release -si) == "Debian" ]] || [[ $(lsb_release -si) == "Ubuntu" ]]
< then
< cd /etc/apt/preferences.d/ || exit 1
< echo -e "Package: nginx*\\nPin: release *\\nPin-Priority: -1" > nginx-block
< fi
---
> # Block Nginx from being installed via yum
> echo "exclude=nginx*" >> /etc/yum.conf
407,411c406,407
< # Remove Nginx APT block
< if [[ $(lsb_release -si) == "Debian" ]] || [[ $(lsb_release -si) == "Ubuntu" ]]
< then
< rm /etc/apt/preferences.d/nginx-block
< fi
---
> # Remove Nginx yum block
> sed -i '/exclude=nginx\*/d' /etc/yum.conf
[root@node-000 nginx-autoinstall-centos]# diff ../nginx-autoinstall/conf/nginx.conf conf/nginx.conf
1c1
< user www-data;
---
> user nginx;
[root@node-000 nginx-autoinstall-centos]# diff ../nginx-autoinstall/conf/nginx-logrotate conf/nginx-logrotate
8c8
< create 640 www-data adm
---
> create 640 nginx adm
Compile and install Nginx from source with optional modules.
- x86, x64, arm*
Debian 8 and laterUbuntu 16.04 and later- CentOS Linux release 7.7
- Latest mainline or stable version, from source
- Optional modules (see below)
- Removed useless modules
- Custom nginx.conf (default does not work)
- Init script for systemd (not provided by default)
- Logrotate conf (not provided by default)
- Block Nginx installation from APT using pinning, to prevent conflicts
- LibreSSL from source (CHACHA20, ALPN for HTTP/2, X25519, P-521)
- OpenSSL from source (TLS 1.3, CHACHA20, ALPN for HTTP/2, X25519, P-521)
- ngx_pagespeed (Google performance module)
- ngx_brotli (Brotli compression algorithm)
- ngx_headers_more (Custom HTTP headers)
- ngx_http_geoip2_module with libmaxminddb and GeoLite2 databases
- ngx_cache_purge (Purge content from FastCGI, proxy, SCGI and uWSGI caches)
- ngx-fancyindex (Fancy indexes module)
- nginx-dav-ext-module (nginx WebDAV PROPFIND,OPTIONS,LOCK,UNLOCK support)
- nginx-module-vts (Nginx virtual host traffic status module )
- See install instructions: nginx-module-vts#installation
Just download and execute the script :
wget https://raw.githubusercontent.com/Angristan/nginx-autoinstall/master/nginx-autoinstall.sh
chmod +x nginx-autoinstall.sh
./nginx-autoinstall.sh
You can check configuration examples for the custom modules.
Just select the option when running the script :
You have the choice to delete the logs and the conf.
To update Nginx, run the script and install Nginx again. It will overwrite current Nginx files and/or modules.
The update feature downloads the script from this repository, and overwrites the current nginx-autoinstall.sh
file in the working directory. This allows you to get the latest features, bug fixes, and module versions automatically.
You can run the script without the prompts with the option HEADLESS
set to y
.
HEADLESS=y ./nginx-autoinstall.sh
To install Nginx mainline with Brotli:
HEADLESS=y \
NGINX_VER=2 \
BROTLI=y \
./nginx-autoinstall.sh
To uninstall Nginx and remove the logs and configuration files:
HEADLESS=y \
OPTION=2 \
RM_CONF=y \
RM_LOGS=y \
./nginx-autoinstall.sh
All the default variables are set at the beginning of the script.
A log file is created when running the script. It is located at /tmp/nginx-autoinstall.log
.
GPL v3.0