Setting up Simple Web Server on RHEL7/Centos7

Introduction to Apache HTTPD

Apache HTTPD is one of the most used web servers on the Internet. A web server is a daemon that speaks the http protocol, a text-based for sending and receiving objects over a network connection. The http protocol is sent over the wire in clear text, using port 80/TCP by default. There is also TLS/SSL encrypted version of the protocol called https that uses port 443/TCP by defaults.

When we browse the Website, Every Website sits on a computer known as a Web Server. This Server always connected to the Internet. DNS Server translates the domain name the user has entered in to its IP address and Web Server are computers that deliver (or serve up) web pages to Users, as shown below.

apache_logo_ittroubleshooter-in

Basic Apache HTTPD Configuration

After installing the httpd package, a default configuration is written to /etc/httpd/conf/httpd.conf

The basic syntax of the httpd.conf file is described as shown below;

httpd_conf_new_ittroubleshooter-in

Outline for Apache Server

Use                              :    Hosting a Website
Port                             :    80/http, 443/https
Configuration files    :    /etc/hhtpd/conf/httpd.conf
Document Root         :    /var/www/html
Daemon                      :    httpd

My setup:

We use 2 systems, One machine as Apache server setup and other machine as a client machine to browse the Website. Let look at below details for more understanding.

Apache server ip address and hostname(Centos7):192.168.1.10 (server1.ittroubleshooter.in)
client machine ip address and hostname(ubuntu):192.168.1.12 (client1.ittroubleshooter.in)

Steps to configure a simple web server

1) Install the package.

The package for Apache web server is “httpd”. We use the yum command to install web server.  If you are not configured the YUM server, refer the link. (Configure the Yum Server in Centos7/RHEL7/Fedora22)

#yum install httpd -y

[root@server1 ~]#  yum install httpd -y

2) Create Simple Welcome page.

Go to “/etc/httpd/conf.d” directory, create a file named as ittroubleshooter.conf (the name doesn’t matter, only the extension should be .conf)

#vim /etc/httpd/conf.d/ittroubleshooter.conf

<Directory /var/www/html>
AllowOverride None
Require all granted
</Directory>

~
~
:wq

As above, every file created in the /var/www/html directory will be displayed by the web-server.
Now create  some simple page on /var/www/html directory.

#vim /var/www/html/index.html

Welcome to ITTroubleshooter

~
~
:wq

Remember: By default new web-server display the welcome page due to the “IncludeOptional conf.d/*.conf” statement at the end of the /etc/httpd/conf/httpd.conf file  that instructs Apache to load the files finishing by *.conf located in the /etc/httpd/conf.d/ directory.

3)Allow httpd service on firewall.

[root@server1 ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@server1 ~]#firewall-cmd --reload
success

4) Start and enable the httpd service.

[root@server1 ~]# systemctl start httpd; systemctl enable httpd

5) DNS configuration if you don’t want to use IP Address.

As we discussed on previous articles how to configure the DNS server, If you are not configured the DNS server, refer the link (Setting up DNS Master-Slave Server Step-by-Step config Guide).

Now, Open the DNS configuration file and add the canonical name as “www”, so that we can use our domain as full fledge website.

#vim /var/named/ittroubleshooter.fwd.zone

$TTL 1D
@  IN SOA  server1.ittroubleshooter.in.  root.ittroubleshooter.in. (
                                 01      ; serial
                                 1D      ; refresh
                                 1H      ; retry
                                 1W      ; expire
                                 3H )    ; minimum
 ; #### Name servers ###########
@       IN      NS      server1.ittroubleshooter.in.
@       IN      NS      server2.ittroubleshooter.in.
 ; #### Resolve Name server hostname to IP Adress #######
@       IN      A       192.168.1.10
@       IN      A       192.168.1.11
 ; #####  Hosts in this Domain #######
@       IN      A       192.168.1.12
@       IN      A       192.168.1.13

 ; #####  Hostname Name maps to IP Adress Using "A" record ######  
server1       IN      A       192.168.1.10
server2       IN      A       192.168.1.11
client1       IN      A       192.168.1.12
client2       IN      A       192.168.1.13

 ; #### DNS "CNAME" records ##########
www     CNAME   server1 

~
~
~
:wq

Restart the DNS services.

[root@server1 ~]# systemctl restart named

6) Verify the status web-server on browser.

To see a Basic web-server, open the browser on client machine and pointing to your server’s hostname or IP address, show below.

httpd_pages_ittroubleshooter-in

To open the website from command line use the following command.

#elinks  192.168.1.10

httpd_elinks_ittroubleshooter-in

You can also use curl command;

#curl<IP Address or Hostname of Web Server>

 Hope this post will help Linux/Unix beginners. Please share you feedback and Comments.!!!

Read Also

Create An Alias Web Site Apache Web Server

Redirect the Website on Apache Web server

Port based hosting on Apache Web server

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz