Part 1 - NGINX Web Server ( Installation & Configuration )
Summary
TLDRThis video script from techbeats.org introduces viewers to Nginx, an open-source web server known for its user-friendly configuration and advanced features. It offers a three-part series starting with the installation and configuration of Nginx on an Ubuntu machine. The tutorial demonstrates how to set up Nginx to serve websites, handle PHP, and create custom web pages. It also covers reverse proxy, load balancing, and mail proxy functionalities. The script guides through editing configuration files, creating custom error pages, and enhancing the server's performance with static content delivery.
Takeaways
- 😀 Nginx is an open-source web server known for its user-friendly configuration files and advanced features, which has gained popularity in various industries.
- 🌐 The video is a part of a three-part series focusing on the installation and configuration of Nginx, including serving websites and running PHP.
- 🔁 Nginx can function as an HTTP server, reverse proxy server, load balancer, mail proxy server, and HTTP cache.
- 🚀 Compared to Apache, Nginx handles concurrent clients and web traffic more efficiently, making it a preferred choice for many web servers worldwide.
- 📈 The open-source version of Nginx is available for use, and it is known for serving static content faster and having a highly scalable architecture with a single-thread handling multiple connections.
- 🛠️ The tutorial demonstrates installing Nginx on an Ubuntu machine using the apt-get package manager and checking its status with systemctl.
- 📝 The script explains how to configure Nginx by editing the 'nginx.conf' file and creating custom server blocks in the 'sites-available' and 'sites-enabled' directories.
- 🌐 It shows how to create a custom welcome page for a website using Nginx by editing HTML files and configuring the server to serve these files instead of the default page.
- 🔗 The video covers how to set up custom error pages in Nginx, providing a more user-friendly experience when content is not found or server errors occur.
- 🛡️ The next part of the video series will cover securing websites with Nginx, including using self-signed certificates and IP whitelisting for enhanced security.
- 📚 The script encourages viewers to subscribe to the channel for more educational content on technology and web development.
Q & A
What is Nginx and why is it gaining popularity?
-Nginx is an open-source web server known for its user-friendly configuration files and advanced features. It's gaining popularity due to its ability to handle concurrent clients and web traffic more efficiently than Apache, as well as its highly scalable architecture.
What are the main functions of Nginx?
-Nginx can function as an HTTP server, a reverse proxy server, a load balancer, a mail proxy server, and also handle HTTP caching.
How does Nginx differ from Apache in terms of performance?
-Nginx can handle more concurrent clients and web traffic better than Apache, making it a preferred choice for high-traffic websites.
What is the process of installing Nginx on an Ubuntu machine?
-Installing Nginx on Ubuntu is straightforward and can be done using the command 'sudo apt-get install nginx', which installs all necessary packages and dependencies.
How can you check if Nginx is installed and running on your system?
-You can check the status of Nginx by typing 'sudo systemctl status nginx' in the terminal, which will show whether Nginx is active and running.
What is the default web page served by Nginx after installation?
-The default web page served by Nginx is a 'Welcome to Nginx' page, which can be accessed by typing 'localhost' in the browser.
How can you create a custom configuration file for Nginx?
-To create a custom configuration file, you need to navigate to the '/etc/nginx/conf.d' directory and create a new file with a '.conf' extension, such as 'techbeast.local.conf', and then define the server settings within this file.
What command can be used to test the Nginx configuration file for any syntax errors?
-The command 'nginx -t' can be used to test the Nginx configuration file for any syntax errors.
How do you reload Nginx to apply configuration changes?
-To apply configuration changes, you should reload Nginx using the command 'sudo systemctl reload nginx'.
Can you customize error pages in Nginx and how?
-Yes, you can customize error pages in Nginx by specifying the location of custom error pages in the configuration file using the 'error_page' directive and linking it to the desired error page files.
How can you serve multiple pages with different content using Nginx?
-You can serve multiple pages with different content by configuring different 'location' blocks within the Nginx configuration file, each serving a different file or directory as needed.
What is the purpose of the 'try_files' directive in Nginx configuration?
-The 'try_files' directive in Nginx is used to specify a list of files that Nginx should attempt to serve in the order listed if the requested URI is not found.
How can you simulate an internal server error for testing purposes in Nginx?
-You can simulate an internal server error by creating a custom location directive that returns a non-existent file or path, which will trigger a 500 error, and then testing the configuration with 'nginx -t' and reloading Nginx.
Outlines
🌐 Introduction to NGINX Web Server
The video script introduces the NGINX web server, an open-source alternative to Apache, known for its user-friendly configuration and advanced features. It's gaining popularity for its ability to handle concurrent clients and web traffic more efficiently. The speaker outlines a three-part series, starting with the installation and configuration of NGINX, and touches on its capabilities as an HTTP server, reverse proxy, load balancer, and mail proxy. The script also compares NGINX with Apache, highlighting its performance and scalability advantages.
🛠️ Installing and Configuring NGINX
This section of the script provides a step-by-step guide on installing NGINX on an Ubuntu machine using the apt-get package manager. It explains how to verify the installation and check the server status. The speaker demonstrates how to serve the default NGINX welcome page and suggests creating custom web pages. The explanation includes navigating to the NGINX configuration directory, understanding the default configuration file, and the process of creating a custom configuration file for a website named 'techbeast.local'.
📝 Customizing NGINX Configuration
The script delves into the details of customizing the NGINX configuration file. It discusses the structure of the configuration, including the server block, listening port, index file specifications, server name, and root directory. The speaker shows how to unlink the default configuration and create a new one using a text editor. The importance of the 'conf.d' directory and 'sites-enabled' folder is highlighted, along with the process of testing the configuration for syntax errors before reloading NGINX to apply changes.
🎨 Creating Custom Web Pages for NGINX
The speaker guides the audience through creating a custom web page for their NGINX server. They start by creating a simple 'index.html' file and explain the process of updating the NGINX configuration to serve this new page. The script also covers moving additional web pages and assets from a cloned repository to the server's document root. The importance of reloading NGINX after making configuration changes is reiterated to ensure the new pages are served correctly.
🔒 Configuring Error Pages and Advanced Routing
The script explains how to configure custom error pages in NGINX, such as 400 and 404 errors, by editing the configuration file to serve specific error documents. It also covers setting up advanced routing for different URL paths, ensuring that NGINX serves the correct content based on the user's request. The speaker provides an example of configuring a 'force' path to serve a 'fast.html' file and demonstrates testing the configuration with a simulated 500 error to show how NGINX serves the custom 50x error page.
🛡️ Securing NGINX and Future Video Content
In the final paragraph, the speaker teases the next part of the series, which will focus on securing the NGINX server. This includes using self-signed certificates for HTTPS, whitelisting IP addresses for access, and implementing other security features. The script concludes with an invitation for viewers to subscribe to the channel for more informative content on technology and web server management.
Mindmap
Keywords
💡nginx
💡Apache web server
💡configuration files
💡reverse proxy server
💡load balancer
💡HTTP server
💡concurrent clients
💡scalability
💡static content
💡custom web pages
💡error pages
Highlights
Introduction to nginx as an open-source web server with user-friendly configuration files and advanced features.
Comparison of nginx with Apache, highlighting nginx's ability to handle more concurrent clients and web traffic.
Explanation of nginx's roles including HTTP server, reverse proxy server, load balancer, mail proxy server, and HTTP cache.
The three-part series structure of the video, starting with installation and configuration of nginx.
Step-by-step guide on installing nginx on an Ubuntu machine using the apt-get command.
Verification of nginx installation and its active status using systemctl.
Demonstration of accessing the default nginx welcome page through curl and a web browser.
Overview of nginx configuration files and directories, including the default configuration file nginx.conf.
Process of creating a custom nginx configuration file and unlinking the default configuration.
Configuration of server block elements such as listen port, index files, server name, and root directory.
Use of nginx -t command to test configuration file syntax and correctness.
Creating custom web pages and serving static content with nginx.
Editing the default nginx webpage to serve a custom index.html file.
Instructions on how to reload nginx to apply configuration changes.
Customization of nginx to serve multiple pages and handle URL paths.
Configuration of custom error pages in nginx for 400 and 404 errors.
Simulating and testing a 500 internal server error with a custom location block.
Setup of a custom 50x error page for internal server errors in nginx.
Teaser for the next video part focusing on securing the nginx server with SSL and IP whitelisting.
Call to action for viewers to subscribe to the channel for more tech-related content.
Transcripts
hey guys welcome to the channel
techbeats.org so today what we are going
to see is all about
nginx nginx is an open source web server
for all your needs basically
so today i think most of us have heard
about apache web server which was um
powering up a lot of websites around the
world for for the past
few years and now nginx is something
like uh booming
and due to its user friendly
configuration files and there are some
advanced features available
uh nginx is now used in a lot of
industries around the world
okay so basically this is a three part
series
and this is a part one of this video and
which is uh installation and
configuration so where i will show you
how to install nginx
in your machine and how you can
configure it how you can serve your own
websites and how you can run php
and all these kind of stuffs using this
nginx web server okay
so what nginx can do for you so
basically it's a http server okay so
when the client is asking something
and the server will respond so basically
uh
it's pretty straightforward okay so it
can act as a
http server and it can act as a reverse
proxy server so
reverse proxy server is something like a
server which is in front of your
main server so instead of server
directly sending you all the information
it will use uh this
reverse proxy server okay so nginx can
act as a reverse proxy server
and it can act as a load balancer so
let's say if you have two or three
servers running on and if you you can
run nginx in front of it and nginx will
balance all the loads uh between these
uh two or three servers which you are
running and it can act as a mail proxy
server and
it can also act as a http catch okay so
there are a lot of
benefits around using this nginx okay
so next why nginx okay so
how it is different from apache and why
uh we should take a look at
nginx in today's scenario so nginx can
handle concurrent clients and more web
traffic okay better than apache so today
already
uh nginx is powering up thousands of web
servers around the world
and a lot a lot of um uh
industries are using this uh nginx okay
as their web server so there are already
open source version is available and
also uh enterprise version is available
so
here uh we are just going to take a uh
take a look at open source version of
this engine x and we are going to set up
everything from the scratch okay
so it can so uh static contents faster
than apache web server so let's say if
you're hosting your um
websites uh somewhere you can consider
using nginx and which will serve files
faster
for the users and it has a highly
scalable architecture
and it's a single thread which can
handle multiple connections okay so
that's some of the features of nginx and
now
straight away i'm gonna take you to uh
hands-on and so let's get our
hands dirty uh by installing afresh
nginx in your machine and how you can
run
or fire up your uh first web application
okay
yeah okay so now i'm in my ubuntu
machine where i'm going to show you how
to install
nginx from the scratch okay so um when
it comes to ubuntu it's always easy to
install packages just by typing soda app
dash
get installed so in the same way
installing nginx is also pretty
straightforward and it is easy
so you can just type sudo
apt dash get install nginx okay
so this will install all the nginx
packages i'm just going to give uh
s and it will install all the uh
dependencies and the packages are needed
for your uh to run the nginx in your
ubuntu machine
okay so it will take a while and you can
see the nginx now
uh successfully installed here so you
can always check the status of this
nginx whether it is successfully
installed and it is running or not
so just by typing sudo system ctl
status nginx okay so this will show you
uh whether nginx is properly installed
and running wow that's great so it's
active and it's running
so now i can just make a simple curl by
typing
localhost okay so this will respond with
a beautiful welcome to nginx webpage
okay so now uh for this video i'm just
using an aws instance machine
so basically uh this is the public ip of
the
machine which i'm using for this video
so now when i just uh reload this page
uh you can see uh okay welcome to nginx
my
my nginx has been the successfully
installed and it's serving a
web page just by saying that uh
everybody i'm running
running in a good condition okay so
so you can always uh you can always uh
create your own custom nginx uh web
pages and to serve your own
static web pages or whatever you want to
run some databases you can use
nginx for that purpose so basically this
is the default webpage
served by nginx and how we can able to
edit it and how we can
able to run our own custom web pages
okay so that is so important so now
for that i am just going to run as a
sudo su so that i don't want to use sudo
command all the time
so let me just go to cd slash atc
ng next okay so this is where all your
configuration file will
be residing okay so slash atc slash
nginx and this is the folder
where all your uh files related to this
nginx will be
available so now uh the default
configuration file is cat
space nginx.conf let me show you uh
what is available inside so basically
nginx will
uh create a user uh www dash data so
this will be the default user which
nginx will
will make use of and it will run this
pid all these process
okay so if you want you can always run
as a root user also okay
so so now uh all the uh
this is the basic uh http configurations
and these are all the
access locks and error locks file which
you can find under where log
nginx folder and this is uh
something important so this is where all
the configuration file uh the custom
configuration file which we are going to
create and we are going to see in this
video will be available inside this conf
dot
d directory okay so and slash nginx
slash sites
enable so basically this two folders uh
nginx server will look for
available configuration files and this
is something for the mail server
okay so which you can make use of okay
to send emails and all these kind of
stuff okay so now
let me just go to this uh
sites dash enable folder okay change
directory sites dash enabled and
you can see uh there is a
file called default which has a link
okay so the file atc
slash nginx slash sites available slash
default this file is already linked uh
to this site enabled folder okay so if
uh we want to create our own custom
configuration file
we need to um unlink this and we want to
edit uh or create our own custom
configuration file
so to do that what i'm going to do is
i'm just going to unlink this
default file okay so now when you
check what is inside this folder there
is nothing okay
so now we have successfully unlinked so
now you can just
go to uh conf d folder
and you can create your own
configuration file for this okay
so now uh let me just name this
configuration as i'm going to create a
uh configuration file for example a nano
tech beast dot local
dot conf so basically this can be
anything so for example if you're
running some
example.com or some xyz.com so you can
just
create a configuration file under the
name example.com.conf
okay so so this is my configuration file
basically so the configuration file uh
it all starts with server okay
so so this is a basic configuration file
which we are going to take a look at
uh now and so the server will always
listen on port 80 by default and if you
want to change
different ports uh you're good to do it
you're good to go and you can do it
so listen 80 the server will listen on
port 80 and
we need to specify the index file okay
so
i'm just going to specify some index
file formats which is index.html
index.html and index.php
so basically this nginx server will look
for this index
files in uh the order which we specify
so index.html index.html and index.php
it will look for the files in this order
okay so now
uh we can give a name for our server so
server name
is something like tech beast dot
local okay so this is the server name
and you can give
a custom name according to your website
which you're going to serve
okay and finally the root directory of
all your
uh website contents okay the html files
and all these files
um we will be available uh inside a
folder and that's that's the root
directory so in my case i'm just going
to
create a folder slash var
www slash tech beast
dot local okay so this will be my uh
configuration uh i mean the the root
folder however all my
html files will be available okay by
default uh engine x will be available
under slash
www.html okay i will show you in a while
so let me save this configuration file
okay so
so maybe the configuration file nginx
has a command
nginx dash t so this command you can
always use
to check whether your configuration file
is uh correct or not
okay in case if you have any errors um
the system will throw error and you can
you can rectify it so now when i type
nginx t
it will show uh your syntax is okay and
the test is successful okay
so as i said now let me show you the
default location of this nginx so when
you install nginx all
your uh configuration file will be
available under change directory slash r
www
html okay so under this uh directory you
can see an index file
so which is the which is the
file which so which is serving this uh
when welcome to nginx page
okay so basically uh so now we are going
we are not going to use this
instead we are asking our configuration
file to tell
uh nginx to use a custom location okay
so now let me just create uh the folder
which we
specified there so make directory
take beast dot local so take b start
local okay that's great
so we have created a folder
techbeast.local and
let me just go to it take base.local so
now there is nothing inside
so uh let me just create a simple
index.html file
index.html file okay so
this is a
simple ng-nex
web page okay just just for
just for our testing okay so that our
nginx and our configuration
um is good to go okay so
that's it so let me just save it
and after you finish all your
configuration changes and everything
uh you should always reload nginx okay
that's the best practice so that all the
configuration changes will take effect
so you can reload your nginx by the
command
system ctl reload nginx okay so this
will reload the nginx and now
when you navigate to your uh web server
and when you reload you can see
the uh your web server is serving
content from the path which you
specified
your custom path so this is a simple
nginx web page okay
that's so great so now uh okay so this
is this is just a text uh which is
showing so we want something um
beautiful and in your case you're going
to host your websites or something else
right
so instead for this video uh you can
just go to this uh
folder which contains some beautiful
index page and some
uh free open source software list of
free open so softwares and some error
pages okay so i will show you how you
can configure
your own custom error pages and all
these kind of stuffs okay
so now uh let me just
uh go to the
root directory uh sorry i mean the home
directory
and let me just clone so git clone
uh this repository okay so this will
clone all the
this will clone the complete uh
repository inside my machine okay
so you can see the nginx dash basics is
available here
so now what i'm gonna do is i'm just
going to move uh all these uh
so files so when you take a look at it
what is inside this nginx basics folder
there's a 400
html file file not xhtml file and some
web pages and some index pages which we
are going to
uh see in a while so i just want to move
all these files inside this wire www
tech beast.local which we created okay
so
uh moo dash v so
slash home ubuntu uh
engine x dash basics star okay slash bar
www uh thickbeast.local
okay okay that's great so now we are
moved almo uh this command will move
all the files and folder inside this uh
tech based.local uh folder
so change directory by www
techbeast.local
so now when i list you can see all the
files already moved here and now
if you go and reload your web page you
can see a beautiful
uh website a simple website welcome to
techbeast.org
and this is a simple welcome page
powered by nginx so in this way you can
serve your own website so you can host
your own websites
uh in a cloud environment and you can
configure the domain name
uh to serve the clients or some
beautiful websites okay
so uh okay so next step so what we are
going to do next we are going to serve
this is just an index page
how i can so multiple pages based on uh
the
requests okay so here for example click
for more open source projects
when i click so it's redirect it's
taking me to a
path called slash foss free open source
software
so this path is not available because we
did not configure this path in our nginx
configuration file
and that's why nginx is serving this for
not for not found error okay
let's go to our configuration file and
configure this path
change directory slash atc nginx conf
d so this is the folder where our
configuration file is available and
just type nanotechbeast.local.com okay
so what we need to do is we need to
configure the
location and the path of the uh for part
of the
url to to make nginx serve the contents
okay
so let me just type location okay so
location slash
so this will serve all the uh this is
the default uh
root path which will solve all the files
for example uh i'm just configuring
uh this location slash by default this
slash is a root directory okay slash
www.local okay so try files
uh uh dollar uri
and dollar uri slash
dollar uri dot html and even a 400
error page okay so basically what i'm
doing is i'm just telling
nginx configuration like whatever the
request coming in this uh
default location you just check whether
files are available
you you can check some other folders uh
subparts and you can check for
a dot html file and you can even uh
return a 400 error page so this is the
default uh configuration
uh location which we need to specify and
now
uh for custom parts for example location
slash
so now we need to serve some contents
okay so when
when the user requests this slash force
there should be some contents to be
served by our nginx okay
so let's just use the same configuration
try
files and dollar uri
and you can just so uh this uh
dot html okay that's great so this is
the
file which is available inside our clone
directory which you just cloned okay
fast.html we're just going to serve this
uh
file when user requests this page okay
so let me just
save my nginx and as i said you can
check your configuration just by typing
nginx
d and my configuration is correct
the syntax is correct and you need to
reload it
system ctl reload
nginx okay so this will reload the
engineering so now
if i go and reload my page you can see
my
nginx is serving a web page with some
beautiful contents okay first
so these are all some list of available
free open source softwares and
in this way you can sew multiple uh
pages okay so multiple pages inside your
website for example
a simple index page a simple about us a
simple portfolio
a contact us page and all these pages
you can serve
using this nginx okay so now
uh let me request for some other pages
which is not available for example
my page so this page we did not
configure so let me just
load it so you can see it's a bad
request because the pages
uh the page which we are requesting is
not available and
nginx was not able to serve it okay
so this this page error pages is
something like a pretty old fashion
right so if you want to create your own
custom error pages
how you can do it you can always
use the nginx configuration files and
you can edit and all these kind of
stuffs you can do
to serve your own custom error pages
okay
let me show you how so
nanotechbeast.local.conf okay so now
let me create a error page a custom
error page
okay so error page okay for example 400
and 404
error slash 400.html
okay so this is the error page which i'm
gonna so
so for that i'm going to going to still
location just specify the location
slash 400.html
and i'm asking nginx to serve this
uh file internally okay
so meaning uh whenever uh a page which
you request is not available nginx will
forward the request internally okay
internally
to serve this 400.html file okay
so that's great so now let me just save
it
okay so let me check the configuration
file and the configuration file is okay
and system ctl reload nginx
okay so this will reload the nginx and
now
let's just reload this page wow that's
great you can see
a custom beautiful uh 400 error page
which we just configured nginx will so
you can search for uh all the files
which is files and location which is not
available for example
uh tech beast there is no such
uh path so page not phone sorry
this is a simple for not x page powered
by nginx okay
so this is something uh which is related
to uh
the request which is not available and
cannot be able to serve with the server
so in case uh there is any issue with
server the server will always
respond with uh some something like 50x
series so
in your day-to-day life if you're using
browsers a lot you should have came
across all these four not x error and
finotex error terms okay
so find it is something like internal
server error and which is related to
server
so how you can serve such uh 50x errors
okay
so let me uh go to the configuration
file
nanotech
so what i'm going to do is i'm just
going to copy the same error page
configuration
and just going to paste it okay so
instead of
400 i'm just going to replace it with
500
502 503 504
and and it will serve
the 50x.html file
fi o x dot html okay same so we are just
asking nginx to
forward it uh internally okay so now let
me save the configuration file
okay sorry before that how we can test
our how we can simulate this 500
uh internal server error okay so then
only we can test
whether our whether the configuration is
working fine or not
okay so so for that what you can do is
you can just create a
custom location uh yellow custom
path which is for 500 error okay
so 500 error so what you can do is
you can just create a error
you can just simulate error by using the
command fast cga
underscore pass and you can just specify
this is this is
error this is something some random path
so
normally this slash this lashes is not
available okay i'm just
simulating a internal server error using
this command okay
so so now i'm just checking whether
everything is correct or not so you
should
make sure that you you always keep the
semicolon at the end of
uh each and every line okay so now
let me just save it okay and
i'm just going to check my configuration
file nginx
t okay that's great my configuration
file looks okay
and i'm going to system ctl reload
nginx i'm just going to reload it okay
so now when i just navigate to 500
error you can see what there seems some
server error
this is a simple 50x page powered by
nginx okay
so in this way you can serve your uh
websites in a in a meaningful way okay
so different parts you can sell
different contents
in case there is an issue with some
pages not found you can serve a for not
for error page
and if there is some internal server
error you can save server
50x pages okay so that is pretty simple
and you can always use nginx
configuration files to achieve all these
kind of stuffs
so thanks for watching guys uh in the
next part of this video i will show you
how you can secure the same website okay
so
created uh by us just now in this part
one of the video and how you can
use your self-signed certificate to
serve content securely
and how you can whitelist the ip
addresses where you can
access your server from and block all
the other sources
sources and some security features we
will take a look at it okay
so thanks for watching guys subscribe to
the channel uh if you feel
uh the channel is really useful for your
career or while building some
fun projects uh feel free to subscribe
and share your comments and let's make
technology easy pc for everyone
thanks for watching
5.0 / 5 (0 votes)