Installing Nginx on Ubuntu 18.04
What is Nginx?
Nginx is a lightweight, open source, high-performance web server designed for serving dynamic and static web content. It is capable of handling a large number of simultaneous connections, making it one of the most popular web servers for powering modern websites.
Nginx is typically used in conjunction with a web application framework such as PHP or Rub. It can also be used as an application server to serve dynamic web content. In addition, Nginx can be used as a reverse proxy server to provide additional services such as caching, load balancing, and SSL termination.
In this tutorial, we will show you how to install Nginx on an Ubuntu 18.04 server.
Prerequisites
Before you begin, you will need:
- A server running Ubuntu 18.04.
- Non-root user with sudo privileges.
You can learn how to create a user with sudo privileges by following the steps in the Initial Server Setup guide for Ubuntu 18.04 server.
Installing Nginx
The Nginx web server is available in Ubuntu’s default repositories, making it possible to install it using conventional package management tools.
By default, the latest version of Nginx available in the Ubuntu 18.04 repositories is 1.14.0. This version may not be the latest version available, but it is stable and supported. We will be using it for this guide.
You can check what version is available for Ubuntu by running the following apt command:
sudo apt update
sudo apt show nginx
Once you have confirmed that the version is the one you want, you can proceed to install Nginx with the following apt command:
sudo apt install nginx
Once the installation is complete, the Nginx service will start automatically. You can verify this by running the following command:
systemctl status nginx
If the service is running, you will see output similar to this:
● 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 Mon 2021-02-12 18:47:23 UTC; 4min 8s ago
Docs: man:nginx(8)
Process: 2224 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 2220 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 2242 (nginx)
Tasks: 2 (limit: 3125)
CGroup: /system.slice/nginx.service
├─2242 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2243 nginx: worker process
Now that the Nginx web server is installed and running, we can move on to configuring it.
Configuring Nginx
By default, the configuration files for Nginx are located in the /etc/nginx directory. Within this Directory, there are several different directories containing files that are used to configure different aspects of Nginx.
The main configuration file is /etc/nginx/nginx.conf. This is the file where you will find all of the main settings for Nginx. In this file, you can adjust the number of worker processes, the log file locations, and set up other options such as using SSL.
In addition to the nginx.conf file, there are other configuration files located in the /etc/nginx directory.
- sites-available: This directory contains configuration files for individual virtual hosts.
- sites-enabled: This directory contains symlinks to the configuration files in the sites-available directory. This allows you to easily enable or disable virtual hosts.
- conf.d: This directory contains configuration files for specific modules. These modules may be provided by a third party.
- proxy.d: This directory contains configuration files for reverse proxy configuration.
If you want to make changes to the configuration of Nginx, you should edit the files in the sites-available directory. This is the recommended way of editing the configuration files. To make the changes active, you will need to create a symlink to the file in the sites-enabled directory.
Testing Nginx
Once you have made the changes to the configuration file, you can test to make sure that they are valid by running the following command:
sudo nginx -t
If the configuration is correct, you will see output similar to the following:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
If there are any errors in the configuration, they will be outputted on the command line. You can then go back and adjust the configuration files accordingly.
Once you have corrected any errors, you can reload the Nginx process with the following command:
sudo systemctl reload nginx
Managing the Nginx Service
Once the Nginx service is installed, you can manage it using the systemctl command.
- To start the service, use the following command:
sudo systemctl start nginx
- To stop the service, use the following command:
sudo systemctl stop nginx
- To restart the service, use the following command:
sudo systemctl restart nginx
- To reload the configuration, use the following command:
sudo systemctl reload nginx
- To enable the service to start at boot, use the following command:
sudo systemctl enable nginx
- To disable the service from starting at boot, use the following command:
sudo systemctl disable nginx
Conclusion
In this tutorial, you have learned how to install and configure Nginx on an Ubuntu 18.04 server. You have also learned how to manage the Nginx service using the systemctl command.
Thank you for reading this article. If you need help setting up an Nginx server or have questions about Nginx, please feel free to leave a comment below. Please also check out our other Nginx articles for more information.
Related Posts:
- Nginx Laravel 5.5 500 NGINX Laravel 5.5 500 What is NGINX Laravel? NGINX Laravel is an open source web server and reverse proxy software that is designed to provide robust web hosting services. It…
- Install Laravel 5.8 Nginx Php7.3 Install Laravel 5.8 Nginx Php7.3 Overview Installing Laravel 5.8 on a Nginx server running PHP 7.3 can be a tricky task. This tutorial explains how to install the popular open…
- Round Robin Load Balancing Nginx Round Robin Load Balancing Nginx What is Nginx and What Does It Do? The Nginx web server is a powerful development and production application server and reverse proxy for running…
- Failed To Start Nginx High Perform Failed To Start Nginx High Perform What Is Nginx? Nginx is an open-source web server software developed by Igor Sysoev in 2002. It is used to serve static and dynamic…
- Digital Ocean Ubuntu Server Nginx Docker Digital Ocean Ubuntu Server Nginx Docker Understanding Digital Ocean Digital Ocean is a cloud service provider that focuses on simplifying web infrastructure for cloud developers. They offer a platform where…
- Nginx Redirect Http To Https With Port Nginx Redirect HTTP To HTTPS With Port Understanding the Basic Terms, Nginx and Redirection Nginx is a popular open source web server commonly used for hosting static web content, providing…
- Nginx Conf Load Balancer Example Nginx Conf Load Balancer Example What is Nginx Conf Load Balancer? Nginx Conf Load Balancer is an open source web server and a reverse proxy server that facilitates the process…
- Nginx Reverse Proxy Subdirectory Laravel Nginx Reverse Proxy Subdirectory Laravel What is Nginx? Nginx is a popular open-source web server used for running web applications. It is fast and can handle large amounts of traffic.…
- Setting Domain Ke Vps Nginx Setting Domain Ke Vps Nginx What is Nginx? Nginx is a powerful web server and popular application development platform that can be used to build efficient web applications. It was…
- How To Setting Nginx For Codeigniter How To Setting Nginx For CodeIgniter What is CodeIgniter and How Does it Work? CodeIgniter is a powerful PHP web programming platform. This open source software framework is greatly preferred…
- Nginx 1.10 3 Ubuntu Nginx 1.10 3 Ubuntu Overview of Nginx Nginx (“engine x”) is an open source web server created by Russian software engineer Igor Sysoev and launched in 2004. It is used…
- Ubuntu Nginx See Real Time Request Ubuntu Nginx - See Real Time Requests Introduction to Nginx on Ubuntu OS Nginx is a powerful, open source web server software that runs in the background of an Ubuntu…
- Nginx Reverse Proxy Apache Change Document Roo Nginx Reverse Proxy Apache Change Document Roo What is Nginx and Apache? Nginx and Apache are two of the most popular open source web servers out there. Nginx is known…
- Laravel Nginx 500 Internal Server Error Laravel Nginx 500 Internal Server Error What is a 500 Internal Server Error? A 500 Internal Server Error is an error code returned by the web server when something has…
- Php Run On Server Apache Nginx PHP Run on Server Apache Nginx What is PHP? PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source scripting language that can be used to create dynamic…
- Nginx Vs Apache Performance 2019 Nginx Vs Apache Performance 2019 What is Nginx? Nginx (pronounced engine-x) is a free, open-source, high-performance HTTP server and reverse proxy. It is much faster than Apache and has been…
- Server Admin Panel For Nginx Server Admin Panel For Nginx What is Nginx? Nginx is an open source web server and content management system developed by Igor Sysoev in 2004. It is known for its…
- How To Count Nginx Scalability How To Count Nginx Scalability What is Nginx? Nginx is an open source web server and reverse proxy server developed by Igor Sysoev. It is a high performance web server…
- Install Nginx Ubuntu Server 16.04 Install Nginx Ubuntu Server 16.04 Introduction to Nginx Nginx is a high performance web server and reverse proxy. It is normally used for serving static content such as images, static…
- Laradock Nginx Exit Duplicate Default Server For… Laradock Nginx Exit Duplicate Default Server For 0.0.0.0:80 In What is Nginx Derived From? Nginx is derived from an open-source and high-performance HTTP server developed by Russian developer Igor Sysoev.…
- Nginx Not Read Index.Php Nginx Not Read Index.Php What is Nginx? Nginx is an open source web server software that is used to serve webpages. It was originally written to handle heavy loads of…
- Stop Nginx Ubuntu 16.04 Stop Nginx Ubuntu 16.04 What is Nginx? Nginx is a web server and reverse proxy software. It is open source and widely used on the web. It is used to…
- Nginx Image For Mobile Apps Json Nginx Image For Mobile Apps Json What is Nginx? Nginx is an open-source web server and reverse proxy for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a…
- Laravel Nginx Not Custom Domain Laravel Nginx Not Custom Domain Overview of Laravel, Nginx, and Custom Domains Laravel is an open-source model-view-controller web application development framework written in PHP. It is the most popular framework…
- Bash Install Nginx On Ubuntu How To Install Nginx On Ubuntu What is Nginx? Nginx is a web server that is gaining popularity in the world of web hosting. Nginx is an open source web…
- Nginx 1.15.12 Http Server Found In Global Scan Data Passive Nginx 1.15.12 HTTP Server Found In Global Scan Data Passive What is Nginx? Nginx is a free, open-source web server created in 2004 by Russian developer Igor Sysoev. Nginx is…
- 404 Not Found Angular Nginx 404 Not Found Angular Nginx What is a 404 Not Found Error? A 404 Not Found Error is an HTTP status code that means that the page you were trying…
- Available Application Apache And Nginx Available Application Apache And Nginx What is Apache? Apache is a web server software that allows users to store and deliver web content quickly and efficiently. Apache was created in…
- Nginx Php-Fpm Php Mariadb Mysql Centos 7.2 Digitalocean Nginx, Php-Fpm, Php, Mariadb, Mysql, Centos 7.2 Digitalocean Introduction: What is Nginx? Nginx is a powerful web server that was first released in 2004. It is known for being a…
- Sudo Systemctl Start Nginx Error Sudo Systemctl Start Nginx Error What is Nginx and How Does it Work? Nginx is an open-source web server created by Igor Sysoev in 2002. It is a lightweight and…