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:
- 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…
- 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…
- 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…
- Nginx Reverse Proxy Node Js < h1 > Nginx Reverse Proxy Node.js < h2 > What is Nginx Reverse Proxy? < p > A reverse proxy is a type of proxy server that takes HTTP(S)…
- Use Https As Default Nginx Use HTTPS as Default Nginx What is Nginx? Nginx is an open-source, high-performance, extensible web server and reverse proxy. It can be used as a web server to serve static…
- 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…
- 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…
- 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…
- Deploy Stand Alone Vue Nginx Deploy Stand Alone Vue Nginx What is Vue.js? Vue.js is an open source JavaScript framework for building user interfaces. It was created by ex-Google employee, Evan You, and is now…
- Nginx Php 5.6 Module Ubuntu 16.04 Nginx Php 5.6 Module Ubuntu 16.04 Overview of Nginx Nginx is a powerful web server that is used to serve both static and dynamic web content. It has become increasingly…
- Nginx Listen To Differnt Port Nginx Listen To Differnt Port What is Nginx? Nginx is an open-source web server software used to serve content to the web. It is used to host web applications and…
- Setting Up Php7 With Nginx Setting up PHP7 With Nginx What is PHP7? PHP7 is the most recent major release of PHP, a server-side scripting language used for dynamic web pages. PHP7 provides accelerated performance,…
- Ubuntu 16.04 Nginx Letsencrypt Ubuntu 16.04: A Comprehensive Guide to Nginx and Letsencrypt What is Nginx? Nginx is a web server and an open-source reverse proxy server for HTTP, HTTPS, and other protocols. It…
- Install Nginx 1.16 Ubuntu Install Nginx 1.16 Ubuntu Introduction to Nginx 1.16 Nginx 1.16 is a web server that helps you to serve web content quickly, efficiently and securely. It is especially popular with…
- 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…
- 502 Bad Gateway Nginx Fix Ubuntu 502 Bad Gateway Nginx Fix Ubuntu What is 502 Bad Gateway? The 502 Bad Gateway is an HTTP status code that shows up when the client computer attempts to communicate…
- Laradock Nginx Exit Duplicate Default Server For 0.0.0.0 80… 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.…
- Forwarding Php And Python To Nginx Web Server Forwarding Php and Python to Nginx Web Server Introduction to Nginx Web Server An Nginx web server is a powerful open-source web server that can handle a wide variety of…
- 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 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…
- 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…
- How To Make Nginx Faster Load How To Make Nginx Faster Load What is Nginx? Nginx is a high-performance web server used in a variety of applications. It is used for web application development, serving static…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…