Playbook

Install Nginx

Nginx from the distribution's packages, enabled and running.

Category

Web servers

Time limit per server

15 minutes

Temporary failures

Retried automatically, up to 2 times

Version

1.0

Supported systems

Ubuntu 22.04+, Debian 12+, RHEL-compatible 8+ (AlmaLinux, Rocky Linux, RHEL, CentOS Stream, Oracle Linux), Amazon Linux 2023+. Still runs on Ubuntu 20.04 and Debian 11, which are past the end of standard support.

When to use it

Before serving websites or putting a reverse proxy in front of an application. The Configure Reverse Proxy playbook and several templates need nginx installed first.

This playbook has no options.

What it does on the server

  1. Installs the nginx package from the distribution's own repositories. An nginx that did not come from the server's packages is used as it is, and only its service is managed.
  2. Before starting nginx, checks that ports 80 and 443 are free. If another program holds one, the run stops and names it.
  3. Runs nginx -t. A configuration that does not pass is not started.
  4. Enables nginx at boot and starts it.

It does not create a site or a virtual host, and it does not change firewall rules.

After the run

Open the server's address in a browser, such as http://203.0.113.10/: you should see the distribution's default nginx page. If you cannot reach it, the firewall is the usual reason. Allow ports 80 and 443 with Advanced Security, listing 80 and 443 under Also allow these ports, and in your cloud provider's firewall or security group.

To serve an application over HTTPS, run Configure Reverse Proxy, or the Nginx Reverse Proxy + Auto-Renewing SSL template.

Common problems

"Port 80 is already in use by …, so nginx cannot start." — Another web server, often Apache (apache2 or httpd), is listening. Stop and disable it if nginx should replace it, or keep that web server and skip this playbook.

"nginx's configuration does not pass nginx -t (above), so it was not started." — A configuration file under /etc/nginx has an error; the output names the file and line. Fix it and run the playbook again.