Using Linux to build HTTP Web server and website log analysis tool Awstats

Source: Internet
Author: User

Server IP Address: 192.168.4.5

Server Host Name: srv5.tarena.com

1. Installing the HTTPD package on the server side

[Email protected]/]# yum-y install httpd

[[Email protected]/]# service httpd start

[Email protected]/]# chkconfig httpd on

2. On client side authentication

Enter 192.168.4.5 in the browser

If the Welcome page is displayed, the server builds successfully

3. Deploying Web page Documents

First remove the Welcome page configuration

[[Email protected] Desktop]# cd/etc/httpd/conf.d/

[Email protected] conf.d]# MV welcome.conf Welcome.conf.bak

Build a Test home page

[Email protected] ~]# cd/var/www/html/

[Email protected] html]# vim index.html

Hello world!

Browser validation

4. Site Directory Migration and default home page settings

[Email protected] html]# mkdir/var/ftp

[[email protected] html]# echo "Wo shi ftp" >/var/ftp/index.html

[Email protected] html]# vim/etc/httpd/conf/httpd.conf

Modify the configuration as follows

DocumentRoot "/var/ftp"

Change the original <directory "/var/www/html" > To <directory "/var/ftp" >

DirectoryIndex index.php index.html Index.html.var

Reload the configuration file

[Email protected] html]# service httpd Reload

Browser validation

5. Disable the use of symbolic links and automatic indexing

[Email protected] ftp]# ln-s/var/www/html/index.html haha.html

Browser Input Validation http://192.168.4.5/haha.html

By verifying that you can use symbolic links by default

Disable Symbolic links below

[Email protected] ftp]# vim/etc/httpd/conf/httpd.conf

<directory "directory path" >

Options-followsymlinks

.. ..

</Directory>

[Email protected] ~]# service httpd restart

When the home page does not exist by default, the index of the directory appears when the site is visited

[email protected] ftp]# RM-RF index.html

Browser validation appears index

Automatic indexing is disabled below

[Email protected] ~]# vim/etc/httpd/conf/httpd.conf

<directory "directory path" >

Options-indexes

.. ..

</Directory>

[Email protected] ~]# service httpd restart

Browser validation error page appears

6. Use directory aliases

[Email protected] ftp]# echo "index" >/usr/src/index.html

[Email protected] ftp]# vim/etc/httpd/conf/httpd.conf

Add a line to the end of the file Alias/tools "/usr/src/"

[Email protected] ftp]# service httpd Reload

Browser input http://192.168.4.5/tools/can access the home page under Server/usr/src/

7. Client Access Control

Allow access from any address

<Directory/var/www/html>

Order Allow,deny

Allow from all

</Directory>


Allow access only from individual network segments, IP addresses

<Directory/var/www/html>

Order Allow,deny

Allow from 192.168.4.0/24 192.168.7.200

</Directory>

8. Enable user authorization for the specified directory

Create a subdirectory under the site root test

can access HTTP./server address/test/

Add user authorization to Studir, allow only user stu01 access (password 123456)

New home page and test catalog

[Email protected] ftp]# echo "Hello World" > index.html

[Email protected] ftp]# mkdir test

Create a new two user with permissions to test (not necessarily a system user)

[Email protected] ftp]# htpasswd-c/etc/httpd/authpwd stu01

[Email protected] ftp]# htpasswd/etc/httpd/authpwd stu02

[Email protected] ftp]# vim/etc/httpd/conf/httpd.conf

<directory "/var/ftp/test" >

AuthName "Tarena Library."

AuthType Basic

Authuserfile/etc/httpd/authpwd

#Require Valid-user//Allow access to test-privileged users

Require user stu01//Allow only stu01 access to the test directory (and the above Require two cannot be used simultaneously)

</Directory>

[Email protected] ftp]# service httpd Reload

Browser input http://192.168.4.5 can be accessed

Input http://192.168.4.5/test/need to enter account and password verification

9. Build Awstats Log Analysis System

Download Awstats Tools

[Email protected] ~]# tar zxf awstats-7.1.tar.gz

[Email protected] ~]# MV Awstats-7.1/usr/local/awstats

[Email protected] ~]# cd/usr/local/awstats/tools/

[Email protected] tools]#./awstats_configure.pl

>/etc/httpd/conf/httpd.conf (fill in httpd configuration file path)

File (required if first install) [y/n]? Y

> srv5.tarena.com (fill in the website domain for log analysis)

>

Press ENTER to continue ...

> http://localhost (server name)/awstats/awstats.pl?config=srv5.tarena.com (website domain name)

View the URL of the log analysis

Press ENTER to finish ...

Modify the Awstats configuration file to specify the log path to log analysis

[Email protected] tools]# vim/etc/awstats/awstats.srv5.tarena.com.conf

Logfile= "/var/log/httpd/access_log" (Specify Log path)

Create a log to parse out the data for the specified directory

[Email protected] tools]# mkdir/var/lib/awstats

Perform log analysis and set up cron scheduled Tasks

[Email protected] tools]#./awstats_updateall.pl now

.. ..

[Email protected] tools]# CRONTAB-E

*/5 * * * */usr/local/awstats/tools/awstats_updateall.pl now

View Analysis Results

Http://192.168.4.5/awstats/awstats.pl?config=srv5.tarena.com

To make it easier to see the results of your analysis, you can place this hyperlink in a Web page on the root of your Web site

[[email protected] ~]# VIM/website root directory/aw-svr5.html

<meta Http-equiv=refresh content= "0;

url=http://Server address/awstats/awstats.pl?config= website domain name >

<body> </body>

Access/HTTP/server address/aw-svr5.html

10. Create a domain-based virtual host

Implement client-to-server domain name resolution by modifying the/etc/hosts file without configuring a DNS server

[Ser5/]# vim/etc/hosts (This step is done at the same time as the server and client)

192.168.4.5 www.baidu.com www.google.com

Create a home directory and homepage for two virtual hosts

[Email protected]/]# Mkdir/var/www/baidu

[Email protected]/]# echo "baidu.com" >/var/www/baidu/index.html

[Email protected]/]# Mkdir/var/www/google

[Email protected]/]# echo "google.com" >/var/www/google/index.html

Create a configuration file for a virtual host

[Email protected]/]# vim/etc/httpd/conf.d/vhost.conf

Namevirtualhost 192.168.4.5

<virtualhost 192.168.4.5>

ServerName www.baidu.com

DocumentRoot "/var/www/baidu"

</VirtualHost>

<virtualhost 192.168.4.5>

ServerName www.google.com

DocumentRoot "/var/www/google"

</VirtualHost>

[Email protected]/]# service httpd Reload

Enter www.baidu.com and www.google.com separately on the client

Note: If you enter the server IP address, open the first virtual host that is set up, because when the virtual host is set up, the site that was originally set up in httpd.conf will not take effect, if you want to change the original in httpd.conf to take effect in the virtual host configuration file, modify the following

Namevirtualhost 192.168.4.5

<virtualhost 192.168.4.5>

ServerName 192.168.4.5

DocumentRoot "/var/ftp"

</VirtualHost>

<virtualhost 192.168.4.5>

ServerName www.baidu.com

DocumentRoot "/var/www/baidu"

</VirtualHost>

<virtualhost 192.168.4.5>

ServerName www.google.com

DocumentRoot "/var/www/google"

</VirtualHost>

then enter HTTP//server IP for authentication


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.