Installing Nginx And Managed By Command (Part 2)
Introduction
in this article, I will install Nginx in a machine, and in part 3 of this series, you will explain about the Nginx file system to make successful configuration and see the Nginx logs of any request or errors.
we need to install Nginx in a local machine or virtual server to handle HTTP requests by it and make our configuration to our services.
in this article, we will see Nginx and where I can find the config file.
we can install Nginx by docker as a container but this article will say about installing the original application inside Ubuntu 20.04 LTS Os.
all parts of Nginx Articles :
- Intro to Nginx Web Server (Part 1)
- you are in part two of the Nginx Series
- Nginx File Configuration and Logs (Part 3)
Installing Nginx
let`s go to installing Nginx in our machine.
the Nginx is available in Ubuntu which means we can use apt to install it.
sudo apt updat
sudo apt install nginxe
we need Adjusting the Firewall
the firewall software need Adjusting to allow access to the service, Nginx registers itself as a service with ufw upon installation.
now we need to work with the list configuration of `ufw`.
sudo ufw app list
after that you must see this result.
OutputAvailable applications:
Nginx Full
Nginx HTTP
Nginx HTTPS
xOpenSSH
from this result you can show you has three profile available from Nginx.
- Nginx Full: this profile open with port 80 (normal, unencrypted web traffic) and port 443 (TLS/SSL encrypted traffic)
- Nginx HTTP: this profile open only port 80
- Nginx HTTPS: this profile open only port 443 (TLS/SSL encrypted traffic)
how i can enable profile with nginx by Ubuntu
you can write the following code in your terminal
- to enable profile.
sudo ufw allow 'Nginx HTTP'
- and we need vitrify changed by the following code.
You can verify the change by typing:
- after write above code you must show this result
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
Nginx HTTP ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Nginx HTTP (v6) ALLOW Anywhere (v6)
now we need a check the web server
in this process must be shown the Nginx is up and ready, but we need to check if it the up and ready by the following code.
systemctl status nginx
and after write above code you should be shown the following result
Output
● 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 Fri 2020-04-20 16:08:19 UTC; 3 days ago
Docs: man:nginx(8)
Main PID: 2369 (nginx)
Tasks: 2 (limit: 1153)
Memory: 3.5M
CGroup: /system.slice/nginx.service
├─2369 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
└─2380 nginx: worker process
now the service is started successfully without any problem
but we need more check if the Nginx is ready we can do this process when calling any page from Nginx
how i can send request to default landing page in Nginx?
you can access the default landing page to check if Nginx start without any problem or not by sending request to your IP address
if don’t know your service IP address you can write the following code
curl -4 icanhazip.com
the icanhazip.com is tools provider your public IP address
when write above code you can send request from your browser to this following
http://your_server_ip
after it, you must show this page.
now the Nginx is running without any problem
how I can manage Nginx by command line:
we can manage the Nginx process when applying the command in your terminal
- to Stop Nginx after started write the following command
sudo systemctl stop nginx
- to start Nginx after stopped write the following command .
sudo systemctl start nginx
- to restart Nginx write the following code
sudo systemctl restart nginx
- if you have new configuration and want apply it you can use the following command.
sudo systemctl reload nginx
- the Nginx by default starts the configuration when boot your web service if don’t need or don’t want to run the configuration you can disable the configuration when applying this command.
sudo systemctl disable nginx
- but if we have re-enabled the configuration we can use this command to do it
sudo systemctl enable nginx
Conclusion:
in this article we installed Nginx and ware see some commands to help managed Nginx like start, stop, and restart.
in the next article, we will explain about Nginx file system and talk about the Nginx files job.
all parts of Nginx Articles :
- Intro to Nginx Web Server (Part 1)
- you are in part two of the Nginx Series
- Nginx File Configuration and Logs (Part 3)
don’t forget to clap on the articles and you can clap 50 times on each article.