Network Services

Web Servers – Start your NGIN…X

These days Web Servers are more than just that.  Web Servers can be used for a variety of things, including be a repository for files that can be used by your infrastructure devices, such as switches, compute, and storage.

In this blog we’ll be installing the NGINX Web application on a CentOS VM (yes…I know).  As a note – the Web Server install in this case in not Internet (Public) facing in the traditional sense, ok? To use NGINX in all its glory, you might want to visit there official website: www.nginx.com.

Again, what we’re doing is building this Web Server for the purposes of holding configuration files for our infrastructure devices.

Alright – so let’s get started.  Normally, I would show a diagram, but all we’re doing is setting up our webserver for a later blog posting. So let’s begin:

Task 1: Download and install CentOS 7 from: https://www.centos.org/download/
I normally choose the ‘Minimal ISO’ because it’s about 800MB compared to 8Gigs of the ‘Everything ISO’

Once installed.  It’s best to perform an update and install net-tools

1
2
[root@dhcp~]# yum -y update
[root@dhcp~]# yum –y install net-tools

Task2: Install the EPEL release for installing NGINX
Run the following command for the epel release

1[root@dhcp~]# yum –y install epel-release

Task 3: Install NGINX service
After the epel release, install the NGINX services with the following command

1[root@dhcp~]# yum –y install nginx

Task 4: Start NGINX Service

Let’s start the NGINX service by issuing the following command

1[root@dhcp ~]# systemctl start nginx

Verify the service with

[root@nginx ~]# systemctl start nginx
[root@nginx ~]# systemctl status nginx
nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since Sat 2018-02-10 21:11:04 EST; 53s ago
Process: 13394 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 13391 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 13389 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 13396 (nginx)
CGroup: /system.slice/nginx.service
├─13396 nginx: master process /usr/sbin/nginx
├─13397 nginx: worker process
└─13398 nginx: worker process 
Feb 10 21:11:04 nginx.lab.aha.local systemd[1]: Starting The nginx HTTP and reverse proxy server...
Feb 10 21:11:04 nginx.lab.aha.local nginx[13391]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Feb 10 21:11:04 nginx.lab.aha.local nginx[13391]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Feb 10 21:11:04 nginx.lab.aha.local systemd[1]: Started The nginx HTTP and reverse proxy server. 

[root@nginx ~]#

As you can see, next to active – our NGINX service is running, yeah!

Task 5: Verify you can reach your NGINX server via a web browser
Open a web browser and enter the ip address of your web browser. From me it will be http://192.168.92.132

Note: If you can’t reach it, probably you might want to check the firewall service on your CentOS VM and clear it using

1[root@nginx ~]# iptables -F

If you’re all set, then enter your IP, your default web Server page should look like this:

If you notice the default location of this web file (index.html). It’s located at: /usr/share/ngnix/html.  In this directory you’ll see a few files to which you can modified to remove the test page we just saw.

If we look into that directory we’ll see the following:

1
2

3
[root@nginx html]# ls
404.html 50x.html index.html nginx-logo.png poweredby.png
[root@nginx html]#

Notice the index.html? Well, this is our default homepage as shown above.  But for our purposes, this webserver is not public facing. To be honest – I’m not much of a web designer either so making great looking web pages is not my thing 🙂 . Again, the purpose is to act as a repository to hold files so our infrastructure devices can download them.  Such file will be patches, startup scripts, ssh keys for automation tools like Anisble (hummm), and etc…

Task 6: Rename index.html and delete it.
We’ll do is copy & rename the index.html to index.html.orig.  I do this because maybe, just maybe, down the road I’ll delve in web building a bit more.

1
2
3

4
[root@nginx html]# cp index.html index.html.orig
[root@nginx html]# ls
404.html 50x.html index.html index.html.orig nginx-logo.png poweredby.png
[root@nginx html]#

Then we’ll have to delete the index.html file

1
2
[root@nginx html]# rm index.html
[root@nginx html]#

Task 7: Add files or directories and verify you can see the file/directory listing
From here you can simply create/add files (or even make additional directory structures) in this directory [/usr/share/nginx/html] and they will appear on the webpage.

When we go back to the webpage, refresh – you’ll see your files listed. Notice my file called Start-your-NGIN…X.

To test if the file will download just click on a file.

Alright – now you have your webserver up & ready for ‘internal’ use. Just add your files for your infrastructure devices and begin automating various aspects of your overall Data Center infrastructure.

Happy Configuring!

Leave a Reply

Your email address will not be published. Required fields are marked *