
Good content takes time and effort to come up with.
Please consider supporting us by just disabling your AD BLOCKER and reloading this page again.
Many of you might be wondering how to install NGINX
and manage it in Linux / Ubuntu OS. In this article I will walk you through the installation process and once the installation is done I will tell you how to manage the NGINX
server.
In NGINX management you will learn how to check NGINX version, verbose output, test configuration, start, stop, restart & reload the NGINX configuration file.
NOTE: Also I will cover NGINXreload
vsrestart
I hope you might have setup Ubuntu 18.04 server in Digital Ocean, Linode or any other cloud servers.
First update your OS package libraries using the following command
sudo apt-get update
Then run the following command to install the NGINX
from Ubuntu package manager
sudo apt-get install nginx
NGINX Help List (-h)
This command lists all the available options for NGINX
sudo nginx -h
With this command you can check which version of NGINX
is installed in your server
sudo nginx -v
By default you wont get to know which all libraries are enabled with NGINX, to know installed libraries then use the following.
sudo nginx -V
You must get the output similar to the following
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-GkiujU/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module
sudo nginx -t
If everything is okay then you will get similar to the following output
#Output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
With -t
you will get to know if the configuration is proper or not. But -T
NGINX it will print the configuration to console
sudo nginx -T
To check the NGINX
status use the following command
sudo service nginx status
You will get similar output as below which tell the status of NGINX
and even few recent logs of NGINX
● 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 Wed 2020-04-22 16:12:15 UTC; 3 days ago
Docs: man:nginx(8)
Main PID: 14023 (nginx)
Tasks: 2 (limit: 1152)
CGroup: /system.slice/nginx.service
├─ 838 nginx: worker process
└─14023 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
Apr 22 16:12:15 stackcoder systemd[1]: Stopped A high performance web server and a reverse proxy server.
Apr 22 16:12:15 stackcoder systemd[1]: Starting A high performance web server and a reverse proxy server...
Apr 22 16:12:15 stackcoder systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Apr 22 16:12:15 stackcoder systemd[1]: Started A high performance web server and a reverse proxy server.
Apr 22 16:13:51 stackcoder systemd[1]: Reloading A high performance web server and a reverse proxy server.
Apr 22 16:13:51 stackcoder systemd[1]: Reloaded A high performance web server and a reverse proxy server.
sudo service nginx stop
sudo service nginx start
After modification of NGINX configuration you can start
, stop
, reload
or restart
NGINX configuration.
sudo service nginx reload
Similar to NGINX reload
you can restart
the NGINX configuration file with the following command
sudo service nginx restart
reload
vs restart
reload
(Safer)When you reload
NGINX configuration file and if NGINX configuration has any errors or issues with the configuration settings then it will abort
the restarting NGINX server with errors displayed to resolve those.
restart
(Not Safer)When you restart
NGINX configuration file and if NGINX configuration has any errors or issues then it will stop
the server and may not possibly restart
NGINX server.
You have learnt how to install and play around with NGINX configuration file. You will also be interested in my other articles related to NGINX
How To Cache Static Files With NGINX Server
Redirect www to a non-www website or vice versa
How To Create Free SSL Certificate With Lets Encrypt/Certbot In Linux (Single / Multiple Domains)
How To Install Linux, NGINX, MYSQL, PHP (LEMP Stack) on Ubuntu
Website Speed and Performance Optimizations
Global Data In All Laravel Blade Pages
Test Your Local Developing Laravel Web Application From Phone Browser Without Any Software
Install Linux, Apache, MYSQL, PHP (LAMP Stack) on Ubuntu
Move Uploaded Files From Local Computer Or Server To Amazon S3 Bucket In PHP
Install Letsencrypt SSL Certificate for RabbitMQ Server and RabbitMQ Management Tool
Create Zip File On The Fly With Streaming Download In PHP Laravel
Search Engine Optimization Concepts
What Is HTTP? Different HTTP Methods And Status Codes Explained With Examples
Testing Laravel Emails With MailHog
SummerNote WYSIWYG Text Editor
Install Apache Web Server On Ubuntu 20.04 / Linux & Manage It