- Server Configuration for ghan.42.fr
- Dockerfile for NGINX Image
- NGINX Container's Entrypoint Shell Script
- Docker Compose for Inception
- NGINX is a popular open source HTTP and reverse proxy server, which was originally written by, a Russian engineer, Igor Sysoev. It can also be set up to function as a mail proxy server, and a TCP/UDP proxy server.
- In addition to the basic feature of serving static and index files, NGINX provides caching feature and load balancing feature, with help from a paid product, NGINX Plus, as a reverse proxy server.
- NGINX can be configured as a HTTP web server or as a reverse proxy. Refer to following guides:
- Refer to following links for setting up NGINX as Wordpress's fastcgi proxy:
- Setting up NGINX and Wordpress by NGINX and by Wordpress
- Refer to the section on TLS and NGINX SSL configuration options.
- NGINX & NGINX Plus can be configured to act as a proxy that distributes requests to pools of multiple web/application servers, under a certain policy, to prevent overloading some servers while there are some idle servers.
- NGINX can replace hardware load balancers or be used in parallel or in series with them. Moving the role of load balancing from physical to logical realm makes load balancing more easy-to-control and cost effective.
- Read how NGINX promotes their load balancing feature from this blog article.
- The way to configure NGINX as a load balancing proxy server and possible options are explained in this link.
- In Linux distributions, NGINX can be installed via their package managers.
apk update && apk add nginx (Alpine Linux)
- But, often the version the package mangers provide are not the latest stable version. In order to install the latest stable version from the repository, provided by NGINX, follow instructions on this link.
-
Once the software is installed and configuration is ready, NGINX can be started by simply running the executable file.
-
When NGINX is run, a master process spawns a number of worker processes. Note that the master process is run as the system's root user and the workers are run as nginx.
- Exposing services that have root access is not recommended for security reasons. However, the root access is necessary to bind to ports that range from 1-1024. Therefore, the master process needs to be run as the root, but by running the workers as non-root user, entrypoints to the root access are hidden. (Check out this discussion.)
- The master process's role is to read and evaluate configration files, and to maintain the worker processes.
- The worker processes distribute connections a server/servers need to handle among themselves such that workload can be distributed to multiple processes. Running multiple processes also increase the amount of system resources a service can utilize (such as file descriptors).
-
When running
- By passing
-s
option with a specific<SIGNAL>
, ab administrator can control a running NGINX service.nginx -s <SIGNAL>
<SIGNAL>
can be one of the following:- quit – Shut down gracefully (the SIGQUIT signal)
- reload – Reload the configuration file (the SIGHUP signal)
- reopen – Reopen log files (the SIGUSR1 signal)
- stop – Shut down immediately (or fast shutdown, the SIGTERM singal)
- Note that
SIGQUIT
is the signal that shuts down the service gracefully. When running NGINX inside docker containers,STOPSIGNAL
must be changed toSIGQUIT
such that the container will stop gracefully whendocker stop
is run.- In this project
STOPSIGNAL
was set by usingstop_signal
directive in docker-compose.yml.... volumes: - wp_resources:/var/www/ghan.42.fr stop_signal: SIGQUIT restart: on-failure ...
- In this project
- After making changes to configuration files, NGINX can be tested by running
nginx -t
. Configuration syntax and availability of files referred in configuration are tested.
- nginx.org. (n.d.). nginx. [online]
- Rick Nelson. (2019). Load Balancing Deployment Scenarios with NGINX. [online]
- Unix & Linux Stack Exchange. (n.d.). Why does nginx starts process as root? [online]
- www.nginx.com. (n.d.). CommandLine | NGINX. [online]
- nginx.org. (n.d.). Controlling nginx. [online]
- Meghna Gangwar. (n.d.). Nginx location directive examples | DigitalOcean. [online]