Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Install NginX HTTP server

Premium
6 min read

We need to install a web-server to our EC2 server, to actually serve our web-project.

  1. To install NginX enter:
root@ip-172-31-44-101:~# apt-get install nginx
  1. Check the status of the NginX server using systemctl status nginx:
root@ip-172-31-44-101:~# systemctl status nginx
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 2022-11-09 17:18:47 UTC; 13min ago
Docs: man:nginx(8)
Main PID: 1679 (nginx)
Tasks: 2 (limit: 1143)
Memory: 1.7M
CPU: 20ms
CGroup: /system.slice/nginx.service
├─1679 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
└─1680 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

MS
Moaz Said ✓ Link copied!

Thanks for this amazing tutorial.. when run this command : apt-get install nginx, have an error E: Could not open lock file /var/lib/dpkg/lock-frontend - open (13: Permission denied) E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?

PK
Povilas Korop ✓ Link copied!

You probably aren't logged in as root, this is covered in previous lessons about SSH connection and logging in, from what I remember.

MS
Moaz Said ✓ Link copied!

I runed all commands of last lectures and no error but this command the same problem

DL
David Lun ✓ Link copied!

This is not a very serious error.

This error usually occurs when a process is functioning to update the system and you try to access the for some other operation. This can be checked if any of apt processes are running by entering ps aux | grep -i apt. If that is the case you should wait until the process is finished and try again, this is common during system updates, note that security updates are being installed automatically.

Another solution might be to reboot the server sudo reboot, and try installing nginx again.

If it does not solve the issue try to kill the process with sudo kill <process id>. Process ids are shown using the previous ps aux | grep -i apt command.

Sometimes the issue may come across a more complex situation, and the issue could be the "lock" files. Lock files restrict access to the system files until a specific operation is performed. Upon completion of the process, the lock will automatically be released to perform further operations of the system. So, to solve this issue you are required to delete the files. Firstly check the lock file using sudo lsof /var/lib/dpkg/lock-frontend.

If you see something "unattended" in the output, wait for this process to complete because the system is working on updates.

Otherwise, get the process ids and terminate them using sudo kill -9 <process id>.

After that, you can delete the lock file sudo rm /var/lib/dpkg/lock-frontend.

Make sure you reconfigure "dpkg" after deleting the lock file sudo dpkg --configure -a

MS
Moaz Said ✓ Link copied!

realy thanks you i solved it

GN
Giang Nguyễn ✓ Link copied!

so how to get SSL (HTTPS)

PK
Povilas Korop ✓ Link copied!

Check out Let's Encrypt