A Web server is a system that
delivers content or services to end users over the Internet. A Web server
consists of a physical server, server operating system and software used to
facilitate HTTP communication. Apache web server is the most widely used web
server application in the world.
BEFORE INSTALLATION WE SHOULD AWARE ABOUT:
1) IMPORTANT FILES & DIRECTORIES:
- /etc/httpd: Main Apache root configuration
directory.
- /etc/httpd/conf.d: Additional Apache configuration
files provided by third party software.
- /etc/httpd/conf/httpd.conf: Main Configuration file.
- /var/lib/httpd/modules: Configuration files for
additional modules.
- /etc/log/httpd: Contains log files
- /var/www: Main web document root
directory.
2) VIRTUAL HOST:
Virtual Hosting is method of hosting
multiple websites on single web server. VirtualHost is a virtual container that
handles web request from clients. In Web Server, there are two type of Virtual Hosting;
(1) Name based and (2) IP based. By Name based Virtual Hosting, we can
configure multiple website on single IP address, whereas in IP based Virtual
Hosting, we can configure only one website on single IP address. We can
configure Virtual Host, by using <VirtualHost> container, like:
<VirtualHost>
ServerAdmin root@server1.example.com
DocumentRoot /var/www/html
ServerName server1.example.com
ErrorLog /var/log/apache/server1.example.com-error_log
CustomLog /var/log/apache/server1.example.com-access_log
DocumentRoot /var/www/html
ServerName server1.example.com
ErrorLog /var/log/apache/server1.example.com-error_log
CustomLog /var/log/apache/server1.example.com-access_log
</VirtualHost>
DISCRIPTION:
<VirtualHost
*:80>: //This ensures the Virtual Host listening on the port 80, change this
to listen on another port.
ServerAdmin: //Server administrator mail ID.
DocumentRoot: //Web documents location.
ServerName: //Domain name of the Virtual Host.
ErrorLog: //Virtual Host Error Log location.
CustomLog: //Allows us to specify the log file name and the log file format (eg Custom Log <path> <format>)
</VirtualHost>: //End of virtual host container.
ServerAdmin: //Server administrator mail ID.
DocumentRoot: //Web documents location.
ServerName: //Domain name of the Virtual Host.
ErrorLog: //Virtual Host Error Log location.
CustomLog: //Allows us to specify the log file name and the log file format (eg Custom Log <path> <format>)
</VirtualHost>: //End of virtual host container.
We can create VirtualHost either in
mail configuration file (/etc/httpd/conf/httpd.conf) or in additional
configuration directory (/etc/httpd/conf.d/*.conf).
3) DOCUMENT UPLOADING:
To upload a document we must use
Document Root. Default Document Root is /var/www/html. To upload a directory we
should create a directory under /var/www.
# mkdir
/var/www/server1DR
Now, we
should create index file in it, with the extension of “.html”.
# vim /var/www/server1DR/index.html
This is my first website.
:wq
This is my first website.
:wq
4) HOST ENTRY:
Apart from
setting up DNS server we should make Host Entry in /etc/hosts. Host entry does
the same work as done by DNS.
# vim /etc/hosts
192.168.1.10 server1.example.com
:wq
192.168.1.10 server1.example.com
:wq
PRACTICAL
OVERVIEW:
IP:
192.168.1.10
Hostname: server1.example.com
DocumentRoot: /var/www/html
ErrorLog: /var/log/apache/server1.example.com-error_log
CustomLog: /var/log/apache/server1.example.com-access_log
Hostname: server1.example.com
DocumentRoot: /var/www/html
ErrorLog: /var/log/apache/server1.example.com-error_log
CustomLog: /var/log/apache/server1.example.com-access_log
Step1: Install httpd package
# yum
install httpd
Step2: Start Apache service
# service
httpd start
Step3: Test default page of Apache
Web Server by using your IP (http://192.168.1.10) OR by using localhost (http://localhost).
You will get this Default Apache page:
Step4: Create Directory for Logs:
# mkdir
/var/log/apache
Step5: Configure your Virtual Host by
using Apache Configuration File:
# vim /etc/httpd/conf/httpd.conf
* Change
Port No at Line #136 OR use default port #80. <<ONLY IF YOU NEEDED>>
* Provide your Virtual Host Name at Line #990. <<TO USE MULTIPLE SITES>>
* Provide your Virtual Host Name at Line #990. <<TO USE MULTIPLE SITES>>
In the last
of the file create your Virtual Host:
<Virtualhost:
192.168.1.10:80>
ServerAdmin root@server1.example.com
DocumentRoot /var/www/html
ServerName server1.example.com
ErrorLog /var/log/apache/server1.example.com-error_log
CustomLog /var/log/apache/server1.example.com-access_log common
</Virtualhost>
ServerAdmin root@server1.example.com
DocumentRoot /var/www/html
ServerName server1.example.com
ErrorLog /var/log/apache/server1.example.com-error_log
CustomLog /var/log/apache/server1.example.com-access_log common
</Virtualhost>
Step6: Create index file in Document
Root, with the extension of “.html”, which will show at the time of site access.
# vim
/var/www/html/index.html
<html>
<body>
<h1>This is my first Website…</h1>
</body>
</html>
:wq
<html>
<body>
<h1>This is my first Website…</h1>
</body>
</html>
:wq
Step7: Make host entry:
# vim
/etc/hosts
192.168.1.10 www.server1.example.com
:wq
192.168.1.10 www.server1.example.com
:wq
Step8: Service Restart:
# service
httpd restart
# chkconfig httpd on
# chkconfig httpd on
Step9: Now check your Web Server by
using IP & site name both:
# wget
server1.example.com OR
# wget http://192.168.1.10
# wget http://192.168.1.10
--2016-05-05
16:16:45-- http://server1.example.com/
Resolving server1.example.com... ::1, 192.168.149.140
Connecting to server1.example.com|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28 [text/html]
Saving to: “index.html.1”
Resolving server1.example.com... ::1, 192.168.149.140
Connecting to server1.example.com|::1|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28 [text/html]
Saving to: “index.html.1”
100%[=======================================================>]
28 --.-K/s in 0s
2016-05-05
16:16:45 (6.71 MB/s) - “index.html.1” saved [28/28]
Step10: If you want to check Logs;
for successful attempts check “access_log” and for unsuccessful attempts check “error_log”.
LOGS FOR SUCCESSFUL ATTEMTS:
# tail –f /var/log/apache/server1.example.com-access_log
192.168.1.10
- - [05/May/2016:1602:34 +0530] “GET /HTTP/1.1” 200 28
192.168.1.10 - - [05/May/2016:1603:34 +0530] “GET /HTTP/1.1” 200 28
192.168.1.10 - - [05/May/2016:1603:34 +0530] “GET /HTTP/1.1” 200 28
LOGS FOR UNSUCCESSFUL ATTEMTS:
# tail –f
/var/log/apache/server1.example.com-error_log
[Thu May 05
16:09:12 2016] [error] [client 192.168.1.10] File does not exist:
/var/www/html/favicon.ico
[Thu May 05 16:09:13 2016] [error] [client 192.168.1.10] File does not exist: /var/www/html/favicon.ico
[Thu May 05 16:09:13 2016] [error] [client 192.168.1.10] File does not exist: /var/www/html/favicon.ico
SPECIAL NOTE:
TO CHECK ERROR LOGS, JUST CHANGE YOUR
NETWORK AND NOW CHECK IT IN BROSWER (e.g. FIREFOX) AND RESTART NETWORK
SERVICES. NOW, YOU WILL NOT GET ACCESS BY IP BUT IF YOU TEST YOUR SITE VIA SITE
NAME, YOU WILL GET ACCESS.
No comments:
Post a Comment