Skip to content
Follow
Ubuntu Linux

How to Install Nginx on Ubuntu Linux

Richard
Written by
Richard
Sep 15, 2021 Updated Jun 20, 2026 4 min read
How to Change Default Apps in Ubuntu
How to Change Default Apps in Ubuntu

You install Nginx on Ubuntu Linux using the apt package manager, typically on Ubuntu 20.04 LTS or newer. Nginx is a powerful, open-source web server that excels at handling high traffic volumes with remarkable speed and efficiency.

Getting Nginx up and running on your Ubuntu system is a straightforward process. You will learn the essential commands to download, install, and verify your Nginx installation.

⚡ Quick Answer

Install Nginx by running `sudo apt update` followed by `sudo apt install nginx`. Check its status with `sudo systemctl status nginx`.

How to use Nginx HTTP server on Ubuntu Linux

Installing Nginx on Ubuntu Linux is straightforward using the apt package manager, which makes it easy to get this popular web server up and running.

Nginx is available in Ubuntu repositories, so we can easily install it using the apt package management tool.

To install Nginx, run the commands below:

🐧Bash / Shell
sudo apt update
sudo apt install nginx

The commands above will install the Nginx HTTP server.

To find out if Nginx is installed and running, use the status check command below.

🐧Bash / Shell
sudo systemctl status nginx

The command will output similar lines below when Nginx is running.

💻Code
nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-09-15 12:27:58 CDT; 9s ago
       Docs: man:nginx(8)
   Main PID: 2711 (nginx)
      Tasks: 2 (limit: 4651)
     Memory: 3.0M
     CGroup: /system.slice/nginx.service
             ├─2711 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             └─2712 nginx: worker process

Sep 15 12:27:58 ubuntu2004 systemd[1]: Starting A high performance web server and a reverse pro>
Sep 15 12:27:58 ubuntu2004 systemd[1]: Started A high performance web server and a reverse prox>

How to allow Nginx through the Ubuntu firewall

If your Ubuntu server’s firewall is on, you’ll need to let Nginx communicate for web traffic, which is easily done using the UFW tool.

If you’re using UFW to manage the Ubuntu firewall, run the below commands to allow traffic.

🐧Bash / Shell
sudo ufw allow 'Nginx Full'

That will allow full traffic to Nginx.

With the firewall opened, simply browse the server hostname or IP address to see if the Nginx default page is up.

💻Code
http://localhost

You should see Nginx default welcome page.

nginx default home page test
nginx default page

How to configure Nginx on Ubuntu Linux

After you install Nginx on Ubuntu, knowing where its main settings are kept is helpful, with all configuration files found in the /etc/nginx directory.

On Ubuntu Linux, these are Nginx directory structures and configuration files.

All Nginx configuration files are located in the /etc/nginx directory. This is considered the Nginx home directory.

Nginx’s main configuration file is /etc/nginx/nginx.conf. Global configuration settings are done in the file, but this file is rarely ever touched.

Nginx Virtual Hosts files are stored in the /etc/nginx/sites-available directory. This is the directory where individual websites are defined. Nginx does not use website configurations until they’re activated. Once activated, they are linked to the /etc/nginx/sites-enabled directory.

These are the command below to activate websites to link them to the /etc/nginx/sites-enable directory. (replace example.com.conf with your VirtualHost file)

🐧Bash / Shell
sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/

The command above will create a symlink of the website configuration files found in the sites-available directory to the sites-enabled directory.

To deactivate a virtual host, use the command below. (replace example.com.conf with your website VirtualHost file).

🐧Bash / Shell
sudo rm /etc/nginx/sites-enabled/example.com.conf

Nginx uses snippets to enhance and add additional functionalities in the /etc/nginx/snippets/ directory.

Snippets only load with Nginx when included within a server block.

You can create snippets and store them in the /etc/nginx/snippets directory. To use the snippets within a server block, use the inclusive definition. Example below:

💻Code
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

 include snippets/mycustomsnippets.conf;

........

Nginx also has log files (access.log and error.log) in the /var/log/nginx/ directory. You can view access and error logs in these files on Ubuntu.

Other Nginx configuration files not listed above might be available in Ubuntu. For more Nginx configurations and how to use them, we’ll continue posting a valuable tutorial here.

Conclusion:

This post showed you how to install and use Nginx on Ubuntu Linux. Please use the comment form below if you find any errors above or have something to add.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04
How to Install KDE Desktop on Ubuntu 24.04
Ubuntu Linux How to Install KDE Desktop on Ubuntu 24.04

55 Comments

Leave a Comment

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