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…
- How To Install Nginx With Varnish Webuzo How To Install Nginx With Varnish Webuzo What is Nginx? Nginx is an open source web server created by Igor Sysoev in 2004. It is a light-weight, robust, high performance…
- Why Nginx Load Balancer Have 504 Error Why Nginx Load Balancer Have 504 Error What is Nginx? Nginx is an open source web server software created to handle HTTP requests efficiently. It is the most popular web…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- Nginx Least Connections Load Balancing Nginx Least Connections Load Balancing What is Nginx? Nginx is an open-source web server which is popularly used for supporting high-traffic websites. It is known for its scalability, reliability, and…
- 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…
- 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…
- 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…
- Connecting Nginx To Smtp Server Php Connecting Nginx To Smtp Server Php What is Nginx? Nginx is an open-source, high-performance web server used for hosting websites and web applications. It is designed for low resource consumption…
- Sudo Systemctl Status Nginx.Service Sudo Systemctl Status Nginx.Service What is Nginx? Nginx is a free, open-source, high-performance web server that claims to offer better performance and scalability than Apache. Nginx also provides a reverse…
- 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 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…
- Site-Available Nginx Whas Delete Ubuntu Site-Available Nginx What Delete Ubuntu What is Nginx and how does it work with Ubuntu? Nginx is a web server designed for high performance, scalability, and reliable internet connectivity. It…
- 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…
- Nginx For Windows With Rtmp Server Nginx For Windows With Rtmp Server What Is Nginx? Nginx is an open source web server that can be used to serve static web pages, dynamic content, and media streams.…
- Nginx Can Not Login Using Reverse Proxy To Apache Nginx Can Not Login Using Reverse Proxy To Apache What is Nginx? Nginx is an open-source, high-performance web server and reverse proxy. It is widely used to improve website performance,…
- 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…
- 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 Test Use Ip For Web Nginx Test Use IP for Web What Is Nginx? Nginx is an open source web server, originally designed as an HTTP server, but is increasingly used in reverse proxy, caching,…
- 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 Install Nginx On Linux Ubuntu How To Install Nginx On Linux Ubuntu What is Nginx? Nginx is a lightweight web server that is widely used for its ability to handle requests efficiently and quickly. It…
- Nginx Http Proxy Http 1.1 Nginx Http Proxy Http 1.1 What is Nginx Http Proxy? Nginx Http Proxy is an open-source web server used to serve web resources such as images, static files, and dynamic…
- Ubuntu Nginx Php-Fpm Short Cut Ubuntu Nginx Php-Fpm Short Cut What Is Nginx? Nginx is a web server software package developed by Igor Sysoev for use with the Linux operating system. It is open source…
- Slim Framework Nginx Alias Php Slim Framework Nginx Alias Php What is Slim Framework? The Slim Framework is a micro web application framework written in PHP to quickly and easily create web applications and APIs.…
- 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…