nginx is one of the most widely utilized web servers in the world. It's currently responsible for hosting some of the largest and most highly trafficked websites on the internet.
This guide will explain how you can install nginx yourself on Ubuntu.
You will need a non-root user with sudo privileges configured on the target server. If such an account is available, log in as the non-root user and begin.
Since nginx is readily available in Ubuntu's default repositories, the installation is straight forward.
First, update your local package index to get the latest package listings by issuing the following command:
$ sudo apt-get update
$ sudo apt-get install nginx
Adjusting Firewall (if enabled)
$ sudo ufw allow 'Nginx HTTP'
$ sudo ufw allow 'Nginx HTTPS'
Ensure nginx is running
At the end of the nginx installation, Ubuntu automatically starts nginx. The web server should be up and running. You can verify with the following command:
systemctl status nginx
If the output shows that nginx is active, go ahead and browse to http://serverdomain_or_IP and verify you're able to see the nginx landing page which should look like this:
Now that nginx on Ubuntu is up and running, look below for a list of some of the basic nginx commands.
Stopping Web Server: sudo systemctl stop nginx
Starting Web Server: sudo systemctl start nginx
Restarting Web Server: sudo systemctl restart nginx
Reload nginx config: sudo systemctl restart nginx
Disable Auto-Start of nginx: sudo systemctl disable nginx
Re-Enable Auto-Start of nginx: sudo systemctl enable nginx
Default Configs and Directories
All the content that the web server displays is located at /var/www/html by default. This is where the default nginx landing page is located. You can alter this by changing the nginx configuration files.
/etc/nginx/nginx.conf - The main nginx configuration file. This file can be modified to make changed to the global configuration.
/etc/nginx/ - The default nginx configuration directory. All of the various nginx configuration files reside here.
/etc/nginx/sites-available/ - The directory where all the server blocks can be stored. nginx does not use any of the configuration files in this directory unless they are linked by a symbolic link to the sites-enabled directory
/etc/nginx/sites-enabled/ - The directory where the server blocks are linked to using symbolic links.
/etc/nginx/snippets - The directory that contains various config fragments that can be included elsewhere in the nginx configuration.
The server logs are located at the following directories by default:
/var/log/nginx/access.log - Every request made to your web server is recorded in this log file unless you've configured nginx to do otherwise.
/var/log/nginx/error.log - Any nginx errors get recorded in this log.
Now that you've installed nginx on Ubuntu, you have a variety of options for the type of content you'd like to serve and technologies you'd like to use in conjunction with nginx.
I recommend that you utilize nginxconfig.io to generate configurations for your nginx installation and the various websites and content you'd like to host. I've covered this tool in a previous blog post you can find HERE.
CommentsWrite a comment ...