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 Static Location For Multiple Django Nginx Static Location For Multiple Django What is Nginx? Nginx is an open source web server written in C that is well-known for its performance and speed. Nginx is one…
- 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…
- 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,…
- 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…
- Google Cloud Ubuntu 16 Install Nginx Php Google Cloud Ubuntu 16 Install Nginx Php 1. What is Nginx? Nginx is a powerful open source web server. It is used to serve web pages to the internet and…
- 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…
- 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…
- Nginx Reverse Proxy For Apache Nginx Reverse Proxy For Apache What is a Reverse Proxy? A reverse proxy is a server that takes incoming traffic from the Internet and forwards it to one or more…
- Performance Php Nginx Vs Nodejs Performance Php Nginx Vs Nodejs Introduction to PHP and Nginx PHP is a widely popular scripting language that is used for web development. It has various features such as the…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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…
- 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 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…
- 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…
- 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…
- 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…
- Nginx Vs Express Whats The Difference Nginx Vs Express: What's The Difference? The History of Nginx and Express Nginx is an open-source web server that has been around for over twelve years. It was created in…
- Nginx Reverse Proxy Vs Haproxy Nginx Reverse Proxy Vs Haproxy What is an Nginx Reverse Proxy? An Nginx Reverse proxy is a web server that fetches content from other web servers. It uses an Nginx…
- 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…
- Nginx Php-Fpm Permission Denied Nginx + PHP-FPM - Permission Denied Issue What is Nginx? Nginx is an open source web server and reverse proxy. It is an ideal platform for building high performance, scalable…
- 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…
- 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…
- E Unable To Locate Package Nginx E Unable To Locate Package Nginx What is Nginx? Nginx is an open-source web server and reverse proxy that is used for hosting websites, web applications, and other network services.…