If you’re thinking of running a website, you’re more likely to go with Nginx or have support for Nginx on web hosting companies than other web servers. Nginx provides powerful features which can be extended by a wide variety of modules. If you’re a student or new user learning Linux, the easiest place to start learning is on Ubuntu Linux. Ubuntu is the modern, open-source Linux operating system for desktops, servers, and other devices. To get started with installing the Nginx HTTP server on Ubuntu Linux, follow the steps below.
How to use Nginx HTTP server on Ubuntu Linux
As mentioned above, Nginx is widely used across the internet. If you want to learn how to install and use it on Ubuntu Linux, then continue below. 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: The commands above will install the Nginx HTTP server. Now, to find out if Nginx is installed and running, use the status check command below. The command will output similar lines below when Nginx is running.
How to allow Nginx through the Ubuntu firewall
If you’re running Ubuntu in protected mode with a firewall enabled, then you’ll have to allow HTTP (80) and HTTPS (443) to the Nginx web server. In most cases, Ubuntu servers are running without a firewall enabled. However, run the commands below if you’re not sure. If you’re using UFW to manage the Ubuntu firewall, then run the commands below to allow traffic. That will allow full traffic to Nginx. With the firewall opened, simply browse to the server hostname or IP address to see if the Nginx default page is up. You should see Nginx default welcome page.
How to configure Nginx on Ubuntu Linux
Now that Nginx is installed, there are important folders and locations that you should be aware of. Other Linux systems might have different folder structures and configuration files. 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. Website configurations are not used by Nginx until they’re activated. Once activated, they are then linked to the /etc/nginx/sites-enabled directory. To activate websites so they’re linked to the /etc/nginx/sites-enable directory, these are the command below. (replace example.com.conf with your VirtualHost file) 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 using the command below. (replace example.com.conf with your website VirtualHost file). Nginx uses snippets to enhance and add additional functionalities and they are located in the /etc/nginx/snippets/ directory. Snippets are only available to load with Nginx when they’re 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: Nginx also has log files (access.log and error.log) located in the /var/log/nginx/ directory. You can view access and error logs in these files on Ubuntu. Other Nginx configuration files might be available in Ubuntu that is not listed above. 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. If you find any error above or have something to add, please use the comment form below.