In this guide, you’ll learn how to install Nginx on your Ubuntu 22.04 LTS and about important Nginx files and directories. Nginx is one of the most popular web servers in the world and is responsible for hosting some of the largest and highest-traffic sites on the internet. It is more resource-friendly than Apache in most cases and can be used as a web server or reverse proxy.
What you’ll learn
- How to set up Nginx
- Some basic Nginx configuration
What you’ll need
- Ubuntu Desktop or Server
- Sudo-privileged user account
- Basic Linux command line knowledge
Install Nginx on Ubuntu
Update your Nginx
$ sudo apt update
Installing Nginx
You can install Nginx using the following command.
You can install nginx using the following command.
$ sudo apt install nginx
techdhee@ubuntu:~|⇒ sudo apt install nginx[sudo] password for techdhee: ================================================================================ Auto-Removing ================================================================================ Package: Version: Size: linux-image-5.13.0-52-g… 5.13.0-52.59 10.3 MB linux-modules-5.13.0-52… 5.13.0-52.59 100.0 MB ================================================================================ Installing ================================================================================ Package: Version: Size: libnginx-mod-http-geoip2 1.18.0-6ubuntu14.2 12 KB libnginx-mod-http-image… 1.18.0-6ubuntu14.2 15 KB libnginx-mod-http-xslt-… 1.18.0-6ubuntu14.2 14 KB libnginx-mod-mail 1.18.0-6ubuntu14.2 46 KB libnginx-mod-stream 1.18.0-6ubuntu14.2 73 KB libnginx-mod-stream-geo… 1.18.0-6ubuntu14.2 10 KB nginx 1.18.0-6ubuntu14.2 4 KB nginx-common 1.18.0-6ubuntu14.2 40 KB nginx-core 1.18.0-6ubuntu14.2 482 KB ================================================================================ Suggested, Will Not Be Installed ================================================================================ Package: Version: Size: fcgiwrap 1.1.0-12 17 KB nginx-doc 1.18.0-6ubuntu14.2 14 KB nginx-doc 1.18.0-6ubuntu14.2 14 KB ================================================================================ Summary ================================================================================ Auto-Remove 2 Packages Install 9 Packages Total download size 696 KB Disk space to free 107.9 MB Do you want to continue? [Y/n] Do you want to continue? [Y/n] Y╭─ Downloading… ───────────────────────────────────────────────────────────────╮│ Total Packages: 9/9 ││ Last Completed: nginx_1.18.0-6ubuntu14.2_amd64.deb ││ Time Remaining: 0:00:00 ━━━━━━━━━━━━━━━ 100.0% • 695.5/695.5 KB • 405.7 KB/s │╰──────────────────────────────────────────────────────────────────────────────╯╭─ Installing Packages ────────────────────────────────────────────────────────╮│Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /…││Setting up: libnginx-mod-http-xslt-filter (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-http-geoip2 (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-mail (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-http-image-filter (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-stream (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-stream-geoip2 (1.18.0-6ubuntu14.2) ││Setting up: nginx-core (1.18.0-6ubuntu14.2) ││* Upgrading binary nginx [ OK ] ││Setting up: nginx (1.18.0-6ubuntu14.2) ││Processing: triggers for man-db (2.10.2-1) ││Processing: triggers for ufw (0.36.1-4build1) ││╭────────────────────────────────────────────────────────────────────────────╮│││✔ Running dpkg … ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 0:00:00 • 23/23│││╰────────────────────────────────────────────────────────────────────────────╯│╰──────────────────────────────────────────────────────────────────────────────╯Notices: Warning: os-prober will not be executed to detect other bootable partitions.Finished Successfullytechdhee@ubuntu:~|⇒ Do you want to continue? [Y/n] Y╭─ Downloading… ───────────────────────────────────────────────────────────────╮│ Total Packages: 9/9 ││ Last Completed: nginx_1.18.0-6ubuntu14.2_amd64.deb ││ Time Remaining: 0:00:00 ━━━━━━━━━━━━━━━ 100.0% • 695.5/695.5 KB • 405.7 KB/s │╰──────────────────────────────────────────────────────────────────────────────╯╭─ Installing Packages ────────────────────────────────────────────────────────╮│Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /…││Setting up: libnginx-mod-http-xslt-filter (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-http-geoip2 (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-mail (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-http-image-filter (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-stream (1.18.0-6ubuntu14.2) ││Setting up: libnginx-mod-stream-geoip2 (1.18.0-6ubuntu14.2) ││Setting up: nginx-core (1.18.0-6ubuntu14.2) ││* Upgrading binary nginx [ OK ] ││Setting up: nginx (1.18.0-6ubuntu14.2) ││Processing: triggers for man-db (2.10.2-1) ││Processing: triggers for ufw (0.36.1-4build1) ││╭────────────────────────────────────────────────────────────────────────────╮│││✔ Running dpkg … ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100.0% • 0:00:00 • 23/23│││╰────────────────────────────────────────────────────────────────────────────╯│╰──────────────────────────────────────────────────────────────────────────────╯Notices: Warning: os-prober will not be executed to detect other bootable partitions.Finished Successfullytechdhee@ubuntu:~|⇒
After installing all required packages we have to start the nginx services using the following command.
sudo systemctl start nginx.service
Use the command below for init.d systems:
sudo systemctl start nginx
Checking your Web Server
$ sudo systemctl status nginx
As confirmed by this output, the service has started successfully. However, the best way to test this is to request a page from nginx.
Now you can open the web browser and in the web browser, you can enter the website link or IP address. But if you are using a local machine then you can use localhost or 127.0.0.1.
If you see the page above, it means that nginx has been successfully installed on your server! Let’s move on.
Some nginx Commands
Now our nginx web server is working on Ubuntu. Let’s go with some management commands of the nginx web server.
To stop the web server or nginx:
sudo systemctl stop nginx
Start the web server or nginx:
$ sudo systemctl start nginx
To restart the web server:
$ sudo systemctl restart nginx
Reload the web server, nginx can often reload without dropping connections. To do this, use this command:
$ sudo systemctl reload nginx
By default, nginx is configured to start automatically when the server boots. If this is not what you want, disable this behavior by using this command:
$ sudo systemctl disable nginx
To re-enable the service to start up at boot. For this, use this command:
$ sudo systemctl enable nginx
This is the way how you install the nginx web server on Ubuntu 22.04 and use your services using the web server.
Conclusion
Now that you have your web server installed, you have many options for the type of content to serve and the technologies you want to use to create a richer experience.
Finally
Thank you for reading this post and keep connected to TECH DHEE to continue enjoying excellent posts. Share your views about this post in the comment section below. If you still have any queries, throw them in the comment section. If you find this post helpful, don’t hesitate to share this post on your social network. It will only take a moment, and also it is quite easy and useful for others.
If you have any questions, feel free to leave a comment.
Related Posts: