How to Install NGINX in Ubuntu

nginx [engine x] is an HTTP and reverse proxy server, a mail proxy server, and a generic TCP/UDP proxy server.

Install NGINX

Installing nginx is pretty easy and starlight forward. To install nginx use the following command(s)

sudo apt-get update
sudo apt-get -y install nginx

These should install and start the web-server service. To check the current status of nginx, use the systemctl commands

sudo systemctl status nginx

If the installation of nginx went properly the above command should produce an output like below

● 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 2018-01-08 10:49:15 CEST; 15s ago
Main PID: 2446 (nginx)
CGroup: /system.slice/nginx.service
        ├─2446 nginx: master process /usr/sbin/nginx -g daemon on; master_process on
        ├─2447 nginx: worker process
        ├─2448 nginx: worker process
        ├─2449 nginx: worker process
        └─2450 nginx: worker process

Jan 08 10:49:15 integration-server systemd[1]: Starting A high performance web server and a reverse
proxy server...
Jan 08 10:49:15 integration-server systemd[1]: Started A high performance web server and a reverse
proxy server.

This shows that the nginx has been installed properly and the service is running. Now we need to configure nginx to serve as per our requirement.

Configure NGINX

Please make sure that the following configurations are available in /etc/nginx/nginx.conf

worker_connections 2000;
server_tokens off;
client_max_body_size 100M;
server_names_hash_bucket_size 128;

Once finish editing /etc/nginx/nginx.conf please check the Nginx config, if it is ok or not by using the following command

sudo nginx -t

The above command should output something like below

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Now, restart nginx for applying these changes.

sudo systemctl restart nginx

Restarting nginx is a personal choice here, you can also reload the configuration without restarting nginx

sudo nginx -s reload

If everything is fine we should be able to see the nginx welcome message in the browser also.

http:<your_server_ip>/

Browser window should look similar to below image

NGINX Welcome Page

Enjoy!