sajad torkamani

This is a quick reference for installing Nginx on Ubuntu 22.04. The same process should work on older Ubuntu versions from at least 16.04 onwards.

Install Nginx package

You can install the default nginx package provided by Ubuntu by running:

sudo apt update && sudo apt install -y nginx

Or if you prefer, you can install the packages from Nginx’s repository. This will make it easier to update. Follow the instructions here.

Disable Apache if installed

If you have Apache installed (check with apache2 --version), you may want to disable it. Apache is often automatically installed when you install PHP.

sudo systemctl stop apache2

Start Nginx service

Upon installation, Nginx should automatically start. Check that it’s running with:

sudo systemctl status nginx

The output of the Nginx service should show Active: active (running). If it’s not running, start it with:

sudo systemctl start nginx

Verify installation

The default Nginx configuration (/etc/nginx/sites-enabled/default) should have Nginx listening on port 80 and serving /var/www/html/index.html.

If you’re installing Nginx on a local machine, browsing to http://localhost should show the default Nginx landing page (or the Apache landing page if you previously had Apache installed).

If you’re installing Nginx on a remote machine (e.g., AWS EC2 instance), browsing to the machine’s public IP address should show the same result.

Nginx landing page

Default Nginx landing page

Apache landing page

Default Apache landing page

Setup server blocks

Now that Nginx is running properly, you’ll want to create server blocks to host multiple domains on your server.

Sources

Tagged: Nginx

Leave a comment

Your email address will not be published. Required fields are marked *