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:
- 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…
- 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…
- 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.…
- Nginx 1.4 6 Ubuntu Nginx 1.4 6 Ubuntu Overview of Nginx 1.4 6 Ubuntu Nginx is an open-source web server software used to serve webpages and HTTP requests. Nginx was initially developed for the…
- 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…
- How To Install Nginx Ubuntu How To Install Nginx Ubuntu What is Nginx? Nginx is an open-source web server, reverse proxy, load balancer, and HTTP cache solution with a strong focus on speed and performance.…
- Nginx Vs Apache Wordpress Benchmark Nginx Vs Apache Wordpress Benchmark What Are Nginx and Apache? Nginx and Apache are two of the most popular web server software applications on the market today. Nginx is a…
- Ubuntu 16.04 Nginx Ipv6 Ubuntu 16.04 Nginx Ipv6 What is Ubuntu 16.04? Ubuntu 16.04 is a version of the Ubuntu Linux operating system for computers and servers. Ubuntu has been around since 2004, and…
- Install Wordpress On Ubuntu Vps On Nginx Install Wordpress On Ubuntu VPS On Nginx What is WordPress? WordPress is an open-source, content management system (CMS) top-tier overall that is used to create powerful online presence. It powers…
- How To Know Apache Or Nginx How To Know Apache Or Nginx Understanding Apache and Nginx Apache and Nginx are two of the most popular web servers used today. Apache is a open-source web server management…
- 502 Bad Gateway Nginx Uwsgi Flask Sock 502 Bad Gateway Nginx Uwsgi Flask Sock What is Nginx? Nginx is an open source, high-performance web server. It is capable of handling a large number of concurrent connections and…
- 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…
- Arrti Nginx 1.2.1 Arrti Nginx 1.2.1 What is Nginx? Nginx is a fast and powerful open-source web server platform that can be used to serve webpages and applications. It is widely used on…
- Ubuntu Server Postgresql Nginx Php Ubuntu Server Postgresql Nginx Php Introduction Optimizing your server is one of the most important steps you can take when it comes to running a successful website or application. It…
- Php 5.6 Fpm Nginx Ssl Php 5.6 Fpm Nginx Ssl What is PHP 5.6 FPM? PHP 5.6 FastCGI Process Manager (PHP 5.6 FPM) is a particular implementation of the fastcgi protocol within the PHP programming…
- What Is Benefit Of Nginx What is the Benefit of Nginx? Overview of Nginx Nginx is a free, open source, high-performance HTTP server, reverse proxy, IMAP/POP3 proxy server, and load balancer. It runs on Linux,…
- What Is The Difference Between Uwsgi And Nginx What Is The Difference Between Uwsgi And Nginx? What Is Uwsgi? Uwsgi stands for “Unicorn web server gateway interface”. It is a powerful, highly configurable and widely used web server…
- Ubuntu Nginx Fastcgi 7.2 Ubuntu Nginx Fastcgi 7.2 What is Ubuntu Nginx Fastcgi? Ubuntu Nginx Fastcgi is an open-source web server that is used to provide web hosting services on Ubuntu Linux. It provides…
- 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…
- 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…
- Default Webserver Nginx Ubuntu 18.04 Default Webserver Nginx Ubuntu 18.04 What is Nginx? Nginx is an open source web server that is used to host websites or act as a reverse proxy for other web…
- Nginx Rtmp Ffmpeg Flv 0x5566cf5df180 Nginx Rtmp Ffmpeg Flv 0x5566cf5df180 Overview of Nginx Rtmp Ffmpeg Flv 0x5566cf5df180 Nginx Rtmp Ffmpeg Flv 0x5566cf5df180 is a powerful streaming media server used for broadcasting live audio, video and…
- Nginx Tuning For Best Performance Nginx Tuning For Best Performance What is Nginx? Nginx (pronounced "engine x") is an open source web server and reverse proxy server for HTTP, SMTP, POP3 and IMAP protocols. It…
- Bridge Tomcat And Express Together With Nginx Bridge Tomcat and Express Together with Nginx What is Tomcat? Tomcat is an open-source web server software developed by the Apache Software Foundation. It is used to serve Java-based websites…
- Reverse Proxy Nginx Dan Windows Server Reverse Proxy Nginx Dan Windows Server Introduction to Reverse Proxy Reverse proxy is a server that is used to receive requests from the Internet and forward them to other servers.…
- Nginx Php-Fpm Php Stack Overflow Articel Nginx Php-Fpm Php Stack Overflow Articel What Is Nginx? Nginx (pronounced engine-x) is an open source web server and reverse proxy software that is popular for its high performance and…
- Deploy Laravel Nginx Ubuntu 18 Deploy Laravel Nginx Ubuntu 18 Intro to Laravel Laravel is a free, open-source, Model-View-Controller (MVC) web framework written in PHP. It has become one of the most popular web development…
- Nginx Com Vs Nginx Org Nginx Com Vs Nginx Org What is Nginx Com? Nginx Com is a commercial and open source web server and a reverse proxy developed and maintained by Nginx Incorporated. Founded…
- Haproxy Nginx X-Forwarded-For Haproxy Nginx X-Forwarded-For What is Haproxy and Nginx? Haproxy and Nginx are two web servers commonly used for load-balancing and hosting websites. Haproxy is a high performance reverse proxy that…
- Nginx More Than 4 Config Nginx More Than 4 Config Basics of Nginx Nginx is a powerful, open source web server. It is designed to be both efficient and secure. It is used to animate…