The superfast, open-source Nginx HTTP webserver is becoming very popular nowadays. Fortunately, it's very simple to install and set it up, as we'll see in this tutorial.
If you want to know about how to securely set up a Linux VPS (Ubuntu & Debian) click here to read my article about just that.
Do not type the
$ sign you see in the command examples in this article. That's just an indicator that you should run the command that follows it in your command line tool.
It's always a good practice to start with everything up to date, so after connecting to your server via SSH, update your Linux distro:
sudo apt-get update sudo apt-get upgrade --show-upgraded
To install Nginx run the following command:
sudo apt install nginx
Now let's make sure it's installed, and which version.
sudo nginx -v
You should see something like this:
"nginx version: nginx/1.18.0"
That should be very close to the latest version!
At any time you want, you can check the status of Nginx, for example, wether it's running.
Let's do that now to see if Nginx is already running. It should be as it's Debian's default behavior, but let's make sure by running the following command:
sudo systemctl status nginx
You should see a bunch of useful information, including something like this:
Active: active (running)
That means Nginx is up and running! 😎
If you're setting up a VPS from scratch, you can now try to access its IP on your browser. You should see something like this:
"Welcome to nginx!"
Congrats! Nginx is up and listening to port 80 (HTTP). If your server is restarted, you don't have to worry about Nginx, it'll be initialized automatically!
You'll probably have to manage Nginx using a few commands throughout your sysadmin activities.
For example, every time you change a website configuration file, or even Nginx's configuration file, you need to reload Nginx so it can take those changes into account. To do that, you run the following command:
sudo systemctl reload nginx
You'll get an error message if there's an error in any configuration file. Otherwise, you won't get any feedback.
There is also the
restart commands that you might need at some point:
sudo systemctl stop nginx
sudo systemctl start nginx
sudo systemctl restart nginx
restart command will
start it again.
You can update Nginx at any time by running:
sudo apt-get update sudo apt-get upgrade nginx
And that's it. You can find more posts related to Nginx and sysadmin in the Related posts section below.
How to set up a website on Linux + Nginx
How to password-protect content on Linux + Nginx
Wildcard HTTPS on Linux + Let's Encrypt + Nginx
What are HTTPS, TLS certificates, and Let's Encrypt?
How to set up a Linux VPS
"Virtual Private Server - Wikipedia" Wikipedia , n.d. Web. 06 May 2014 <http://en.wikipedia.org/wiki/Virtual_private_server>
How to install Nginx on Linux by Flavio Silva is licensed under a Creative Commons Attribution 4.0 International License.