NGINX is a high performance HTTP server allowing for load balancing. It allow to serve a great number of visitors while using less CPU and RAM than Apache2.
This howto is tested on:
- Debian 9.0 Stretch
- Debian 10.0 Buster
This howto is tested with these versions on the software:
- 1.10.3
Installation
Detect if sudo is available (“command” is used if not):
cmdProxy='command'
command type -f 'sudo' &>'/dev/null' && cmdProxy='sudo'
Third-party software repository setup (optional)
Setup the third-party software repository to install the latest NGINX version, and not the one provided by Debian.
Install the software requirements:
${cmdProxy} apt install 'lsb-release'
Detect the distribution version name:
debianVersion="$(command lsb_release -cs)"
Add the repository signing key to APT configuration:
command wget --quiet --no-check-certificate --output-document=- \
'https://nginx.org/keys/nginx_signing.key' \
| ${cmdProxy} apt-key add -
Add the third-party software repository to APT configuration, if it exists:
if command wget --spider --no-check-certificate --quiet "https://nginx.org/packages/mainline/debian/dists/${debianVersion}/nginx/"; then
${cmdProxy} tee '/etc/apt/sources.list.d/nginx.list' <<< \
"# NGINX latest version.
deb https://nginx.org/packages/mainline/debian/ ${debianVersion} nginx
deb-src https://nginx.org/packages/mainline/debian/ ${debianVersion} nginx"
fi
Update the list of available packages:
${cmdProxy} apt update
Software installation
Install the HTTP server:
${cmdProxy} apt install 'nginx'
Start the software at boot:
${cmdProxy} systemctl enable 'nginx'
Configuration
If the package use is not the one provided by Debian, configure the modules-enabled mechanism:
if ! grep -q 'include /etc/nginx/modules-enabled/*.conf;' '/etc/nginx/nginx.conf'; then
${cmdProxy} mkdir --parent '/etc/nginx/modules-available'
${cmdProxy} mkdir --parent '/etc/nginx/modules-enabled'
${cmdProxy} sed -i -e '/^pid/a\
# Include enable modules configuration.\
include /etc/nginx/modules-enabled/*.conf;' '/etc/nginx/nginx.conf'
fi
If the package use is not the one provided by Debian, configure the sites-enabled mechanism:
if ! grep 'include /etc/nginx/sites-enabled/*;' '/etc/nginx/nginx.conf'; then
${cmdProxy} mkdir --parent '/etc/nginx/sites-available'
${cmdProxy} mkdir --parent '/etc/nginx/sites-enabled'
${cmdProxy} tee '/etc/nginx/conf.d/sites-enabled.conf' <<< \
"# Include enabled sites configurations.
include /etc/nginx/sites-enabled/*;"
fi
If the package use is not the one provided by Debian, install the PHP FPM configuration snippets:
${cmdProxy} mkdir --parent '/etc/nginx/snippets'
test -e '/etc/nginx/snippets/fastcgi-php.conf' \
|| ${cmdProxy} wget --quiet --output-document='/etc/nginx/snippets/fastcgi-php.conf' \
'https://raw.githubusercontent.com/biapy/howto.biapy.com/master/nginx/fastcgi-php.conf'
test -e '/etc/nginx/fastcgi.conf' \
|| ${cmdProxy} wget --quiet --output-document='/etc/nginx/fastcgi.conf' \
'https://raw.githubusercontent.com/biapy/howto.biapy.com/master/nginx/fastcgi.conf'
Next steps
This howto recommends:
PHP
This howto recommends the installation of PHP by following:
- Install PHP-FPM on Debian.
- Install php-tools, command-line tool easing PHP configuration.
- Improve PHP initial configuration on Debian.
Administration
Test NGINX configuration (allow to detect configuration errors without applying the new configuration) :
sudo nginx -t
Reload server configuration without interrupting the service :
sudo systemctl 'reload' 'nginx'
Reload the server configuration by restarting the server without closing existing connections (no HTTP error) :
sudo systemctl 'force-reload' 'nginx'
Reload the server configuration by closing existing connections (a HTTP error is displayed to the user) :
sudo systemctl 'restart' 'nginx'
Thanks
- Thanks to NGINX (en) developers.
- Thanks to Korben (fr) for Mettre en place un Reverse Proxy Nginx sur son serveur (fr).
- Thanks to Angristan (fr) for Configurer HTTPS sur Nginx (fr).
- Thanks to DigitalOcean (en) for How To Migrate from an Apache Web Server to Nginx on an Ubuntu VPS (en).
- Thanks to easyengine (en) for Debugging Nginx Configuration (en).
- Thanks to Josh Sherman (en) for How to install the latest nginx on Debian and Ubuntu (en).
- Thanks to Raymii.org (en) for Strong SSL Security on nginx (en).
0 Comments